Sun Java Solaris Communities My SDN Account Join SDN
 
Quizzes

Java 2 Collections Quiz

 

Quizzes Index

2 Collections Quiz
Duke

In his book Java Collections, John Zukowski explained the Collections Libraries. Now, show what you know!

 

1. Which of the following is not in the same class hierarchy?

 A. Map
 B. List
 C. Collection
 D. Set


2. The Hashtable class has been retrofitted into the Collections Framework. Which of the following interfaces does it implement?

 A. Map
 B. List
 C. SortedMap
 D. Set


3. Which method doesn't belong with the respective interface?

 A. Comparable - compareTo()
 B. Comparator - equals()
 C. ListIterator - getPrevious()
 D. Iterator - remove()


4. If you had an array of the following type stored in the variable theArray, which cannot be sorted with Arrays.sort(theArray)?

 A. String
 B. int
 C. BigDecimal
 D. URL


5. If you try to add an element to a list after calling the unmodifiableList() method of Collections, which exception will be thrown?

 A. UnsupportedOperationException
 B. NotSupportedException
 C. OperationNotSupportedException
 D. OperationalException


6. True or False. WeakHashMap is a subclass of HashMap.

 A. True
 B. False


7. Which of the following is true about HashMap and Hashtable?

 A. Both require their keys to be strings
 B. Both maintain key-value pair references in insertion order
 C. Both provide synchronized access
 D. Both can directly hold primitive and object values
 E. None of the above


8. Which of the following variable types cannot be used as an index for an array?

 A. byte
 B. int
 C. long
 D. char


9. If you want to create a custom Set by subclassing the AbstractSet class, which methods must you implement?

 A. add(), remove(), iterator(), and size()
 B. iterator() and size()
 C. iterator(), size(), equals(), and hashCode()
 D. iterator()


10. True or False. The StringTokenizer class implements the Enumeration interface. With the 1.2 release of the J2SE, it was modified to also implement the Iterator interface.

 A. True
 B. False