The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Collections
Lesson: Interfaces

Questions and Exercises: Interfaces

Questions

  1. Which two of the following interfaces are at the top of the hierarchies in the Java Collections Framework?
    • Set
    • Map
    • Queue
    • SortedMap
    • Collection
    • List
  2. Which of the following interfaces does not allow duplicate objects?
    • Queue
    • Set
    • List
  3. In order for objects in a List to be sorted, those objects must implement which interface and method?
  4. True or false: The element method alters the contents of a Queue.

Exercises

  1. Write a method with the signature:
    public Collection<String> filter(Collection<String> c)
    
    that (1) traverses through the elements in c using an Iterator, (2) checks whether each element meets a certain condition (in a separate method condition which you do not need to define right now), and (3) if the object meets the condition, adds it to the new Collection to return. The method should not modify the Collection c. Design the method to work on any collection of Strings. Only the condition method should have application-specific code; we will define this method as part of an application in the exercises for the Implementations lesson.
  2. Write a method with the signature:
    public List<Integer> reverse(List<Integer> orginalList)
    
    that returns a new List that contains the same Integer objects as the originalList argument, but in reverse order. The method should not modify the orginalList object.
Check your answers. (in the Collections trail)
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.