Question 11 pts
Which of the following is NOT one of the 3 main categories of collections? In other words, which of these objects does not, itself, represent a collection of items?
Flag this Question
Question 21 pts
Which of the following is true about Lists and Sets?
| Lists are indexed; Sets are not. |
| Lists may contain duplicate items; Sets do not. |
Flag this Question
Question 31 pts
Which of the following may be used to examine every item in the List myList?
Option A:
for( int i = 0; i < myList.size( ); i++ ) System.out.println( myList.get( i ) );
Option B:
for( String s : myList ) System.out.println( s );
Option C:
Iterator it = myList.iterator( ); while( it.hasNext( ) ) System.out.println( it.next( ) );
| Either A or B, but not C. |
Flag this Question
Question 41 pts
Which of the following may be used to examine every item in the Set mySet?
Option A:
for( int i = 0; i < mySet.size( ); i++ ) System.out.println( mySet.get( i ) );
Option B:
for( String s : mySet ) System.out.println( s );
Option C:
Iterator it = mySet.iterator( ); while( it.hasNext( ) ) System.out.println( it.next( ) );
| Either B or C, but not A. |
Flag this Question
Question 51 pts
Every key in a Map must be unique. What happens when a Map receives a 'put' message specifying a key that is already used in the Map?
| A DuplicateKeyException is thrown. |
| The map entry for the key is updated -- its associated value is replaced by the new value specified, and the old value is returned by the 'put' method. |
| The map entry for the key is updated -- its associated value is replaced by the new value specified, and null is returned by the 'put' method. |
| The map entry for the key is updated -- the new value specified is added to the list of values associated with the key. |
| No change is made to the Map, and the 'put' method returns null. |
Flag this Question
Question 61 pts
Which of the following could be an "expensive" operation (an operation that takes a long time to complete) in an ArrayList?
| adding a new item at the end of the list when size( ) is less than capacity |
| adding a new item at the beginning of the list |
| using get(itemNumber) to examine a list item in the middle of the list |
| iterating through the list |
Flag this Question
Question 71 pts
Which of the following could be an "expensive" operation in the SimpleLinkedList class we discussed?
| adding a new item at the end of the list |
| adding a new item at the beginning of the list |
| using get(itemNumber) to examine a list item in the middle of the list |
| calling 'next()' using an iterator provided by the list |
Flag this Question
Question 81 pts
What will be the contents of myList, in the correct order, after the following sequence of operations? (Assume all operations are supported by the list implementation used.)
List myList = ... // create new, empty list myList.add( "red" ); myList.add( "green" ); myList.add( "red" ); myList.add( 1, "black" );
| [ "red", "green", "red", "black" ] |
| [ "black", "green", "red" ] |
| [ "red", "black", "green", "red" ] |
| [ "black", "red", "green" ] |
| [ "red", "black", "red" ] |
Flag this Question
Question 91 pts
What will be the contents of mySet, regardless of order, after the following sequence of operations? (Assume all operations are supported by the set implementation used.)
Set mySet = ... // create new, empty set mySet.add( "red" ); mySet.add( "green" ); mySet.add( "red" ); mySet.add( "black" );
| [ "red", "green", "red", "black" ] |
| [ "black", "green", "red" ] |
Flag this Question
Question 101 pts
What will be the contents of myMap, regardless of order, after the following sequence of operations? (Assume all operations are supported by the map implementation used.) Answers are shown as key=value pairs.
Map myMap = ... // create new, empty map myMap.put( "red", "green" ); myMap.put( "orange", "blue" ); myMap.put( "red", "yellow" ); myMap.put( "blue", "black" );
| [ "red"="green", "orange"="blue", "red"="yellow", "blue"="black" ] |
| [ "orange"="blue", "red"="yellow" ] |
| [ "red"="green", "orange"="blue" ] |
| [ "red"="yellow", "blue"="black" ] |
| [ "orange"="blue", "red"="yellow", "blue"="black" ] |