Array Lists, Searching arrays and Iterators Flashcards

1
Q

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?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the correct way to access an item with an index of 4 in an ArrayList of Strings called list?

A

String x = list.get(4);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If ArrayList’s indexOf method is called, with a value that does not exist in the array list, what is returned?

A

-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False?
Arrays can hold primitive and object types
ArrayLists can hold only object types

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False?

Iterators work with standard Arrays as well as ArrayLists

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What method lists all the safe ways to delete items in an array list whilst looping through it?

A

Using an Iterator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False?

An ArrayList may be created with an initial capacity

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the correct way to get the number of items in an ArrayList called carsList?

A

carsList.size()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can the contents of an ArrayList be most easily placed in a standard Array?

A

Using the ArrayList’s toArray() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly