CPSC426 Java EH411

Exercise/Homework EH41

Q1: Which of these is not an example of a "real-life" collection?

  1. The cards you hold in a card game.
  2. Your favorite songs stored in your computer.
  3. The players on a soccer team.
  4. The number of pages in a book.

ANS:

Q2: The Java collections ______provides standardized collections intended for broad reuse.

  1. Frameset.
  2. Framework.
  3. Framegroup.
  4. Frametable.

ANS:

Q3: Which statement is false?

  1. A collection is an object that can hold references to other objects.
  2. The collection interfaces declare the operations that can be performed on each type of collection.
  3. Unfortunately, collections discourage software reuse because they are non-portable.
  4. 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 ______.

  1. java.util.
  2. javax.swing.
  3. java.collections.
  4. 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.

  1. sort, binarySearch.
  2. sort, fill.
  3. binarySearch, equals.
  4. binarySearch, fill.

ANS:

Q6: Class Arrays provides method ______for comparing arrays.

  1. compare.
  2. compares.
  3. equal.
  4. equals.

ANS:

Q7: Interface ______allows a program to walk through the collection and remove elements from the collection.

  1. Set.
  2. Queue.
  3. Iterator.
  4. List.

ANS:

Q8: Interface Collection contains ______operations (i.e., operations performed on the entire collection).

  1. aggregate.
  2. composite.
  3. integral.
  4. bulk.

ANS:

Q9: Which statement is false?

  1. A List is an ordered Collection.
  2. A List cannot contain duplicate elements.
  3. A List is sometimes called a sequence.
  4. Lists are zero based.

ANS:

Q10: Which of the following does not implement interface List?

  1. ArrayList.
  2. LinkedList.
  3. Vector.
  4. ListIterator.

ANS:

Q11: Which statement is false?

  1. A ListIterator accesses the elements of a List.
  2. Class ArrayList is a fixed-size array.
  3. A LinkedList is a linked list implementation of a List.
  4. ArrayLists execute faster than Vectors because they are not thread safe.

ANS:

Q12: Iterator method ______determines whether the Collection contains more elements.

  1. hasNext.
  2. next.
  3. contains.
  4. containsNext.

ANS:

Q13: LinkedList method listIterator returns a(n) ______.

  1. Iterator.
  2. List.
  3. sub list.
  4. bidirectional iterator.

ANS:

Q14: Which statement is false?

  1. When a List is backed up with an array, any modifications made through the List view change the array.
  2. When a List is backed up with an array, any modifications made to the array change the List view.
  3. 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.
  4. 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.

  1. capacity.
  2. length.
  3. size.
  4. contains.

ANS:

Q16: Which statement is false?

  1. If you do not specify a capacity increment for a Vector, the system will automatically choose a default value of 10.
  2. Inserting additional elements into a Vector whose current size is less than its capacity is a relatively fast operation.
  3. It is a relatively slow operation to insert an element into a Vector that needs to grow larger to accommodate the new element.
  4. 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.