I have a quiz program but a small section is not working. Basically, I have an ArrayList<Object>
that holds 10 (or more, doesnt matter) Question Objects that I can refer to later.
Anyway, when I want to use ArrayList.remove(index)
, it doesn't remove that object! I honestly do not know what to do.
(Key Search is another class that takes in a string (key) and searches the quiz arraylist for it. It returns an arraylist of the questions that DO NOT contain the key word, thus letting me remove them from the overall question array.)
ArrayList<Integer> indexAt = new ArrayList();
indexAt = keyWord.indexAt(); //returning the questions that need to be removed
System.out.println("(1) Number of Questions: " + Questions.size()); //debugging
for(int i = 0; i < indexAt.size(); i++)
{
Questions.remove(indexAt.get(i));
}
//prints out the questions that were removed (for my own reasoning)
for(int i = 0; i < indexAt.size(); i++)
{
System.out.println(indexAt.get(i));
}
System.out.println("(2) Number of Questions: " + Questions.size()); //debugging
Sorting sort = new Sorting(Questions);
The output looks like this:
(1) Number of Questions: 10
1
2
3
4
6
(2) Number of Questions: 10
It should've removed indexes 1,2,3,4,6!!