CPSC426 Java EH411
Exercise/Homework EH41
Q1: Which of these is not an example of a "real-life" collection?
- The cards you hold in a card game.
- Your favorite songs stored in your computer.
- The players on a soccer team.
- The number of pages in a book.
ANS:
Q2: The Java collections ______provides standardized collections intended for broad reuse.
- Frameset.
- Framework.
- Framegroup.
- Frametable.
ANS:
Q3: Which statement is false?
- A collection is an object that can hold references to other objects.
- The collection interfaces declare the operations that can be performed on each type of collection.
- Unfortunately, collections discourage software reuse because they are non-portable.
- Collections are carefully constructed for rapid execution and efficient use of memory.
ANS:
Q4: The classes and interfaces which comprise the collections framework are members of package ______.
- java.util.
- javax.swing.
- java.collections.
- java.collection.
ANS:
Q5: ClassArraysmethodssort, binarySearch, equals and fill are overloaded for primitive-type arrays and Object arrays. In addition, methods ______and ______are overloaded with generic versions.
- sort, binarySearch.
- sort, fill.
- binarySearch, equals.
- binarySearch, fill.
ANS:
Q6: Class Arrays provides method ______for comparing arrays.
- compare.
- compares.
- equal.
- equals.
ANS:
Q7: Interface ______allows a program to walk through the collection and remove elements from the collection.
- Set.
- Queue.
- Iterator.
- List.
ANS:
Q8: Interface Collection contains ______operations (i.e., operations performed on the entire collection).
- aggregate.
- composite.
- integral.
- bulk.
ANS:
Q9: Which statement is false?
- A List is an ordered Collection.
- A List cannot contain duplicate elements.
- A List is sometimes called a sequence.
- Lists are zero based.
ANS:
Q10: Which of the following does not implement interface List?
- ArrayList.
- LinkedList.
- Vector.
- ListIterator.
ANS:
Q11: Which statement is false?
- A ListIterator accesses the elements of a List.
- Class ArrayList is a fixed-size array.
- A LinkedList is a linked list implementation of a List.
- ArrayLists execute faster than Vectors because they are not thread safe.
ANS:
Q12: Iterator method ______determines whether the Collection contains more elements.
- hasNext.
- next.
- contains.
- containsNext.
ANS:
Q13: LinkedList method listIterator returns a(n) ______.
- Iterator.
- List.
- sub list.
- bidirectional iterator.
ANS:
Q14: Which statement is false?
- When a List is backed up with an array, any modifications made through the List view change the array.
- When a List is backed up with an array, any modifications made to the array change the List view.
- The only operation permitted on the view returned by Arrays method asList is delete, which deletes the value from the view and the backing array.
- Adding elements to the view returned by Arrays method asList results in an UnsupportedOperationException.
ANS:
Q15:Vector method ______determines the number of elements currently in the Vector.
- capacity.
- length.
- size.
- contains.
ANS:
Q16: Which statement is false?
- If you do not specify a capacity increment for a Vector, the system will automatically choose a default value of 10.
- Inserting additional elements into a Vector whose current size is less than its capacity is a relatively fast operation.
- It is a relatively slow operation to insert an element into a Vector that needs to grow larger to accommodate the new element.
- A reference to an object of any class type can be stored in a Vector.
ANS:
Q17: Write a program that reads in a series of first names and stores them in a LinkedList. Do not store duplicated names. Allow the user to search for a first name.