Array Lists, Searching arrays and Iterators Flashcards
Consider the following code.
public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(3); list.add(2); list.add(1); list.add(0); deleteEntry(list,2); System.out.println(list.get(2)); }
static void deleteEntry(ArrayList list, int index){
list.remove(index);
}
What is output when the main method is executed?
0
What is the correct way to access an item with an index of 4 in an ArrayList of Strings called list?
String x = list.get(4);
If ArrayList’s indexOf method is called, with a value that does not exist in the array list, what is returned?
-1
True or False?
Arrays can hold primitive and object types
ArrayLists can hold only object types
True
True or False?
Iterators work with standard Arrays as well as ArrayLists
False
What method lists all the safe ways to delete items in an array list whilst looping through it?
Using an Iterator
True or False?
An ArrayList may be created with an initial capacity
True
What is the correct way to get the number of items in an ArrayList called carsList?
carsList.size()
How can the contents of an ArrayList be most easily placed in a standard Array?
Using the ArrayList’s toArray() method