Java Reference
In-Depth Information
16. NavigableSet<Integer> subset = tree.subSet(new Integer(7), false,
new Integer(14), true);
17. for(Integer x : subset) {
18. System.out.print(x + “ “);
19. }
The previous statements break down as follows:
1. Line 12 retrieves the ceiling of 10 , which is the smallest element greater than or
equal to 10 , which is 10 .
2. Line 14 retrieves the higher of 10 , which is the smallest element greater than 10 ,
which is 11 .
3.
Line 16 retrieves a subset of tree from 7 (noninclusive) and 14 (inclusive), which is
8 to 14 . The for-each loop on line 17 outputs this subset.
The output of the code is
ceiling of 10 = 10
floor of 10 = 11
8 9 10 11 12 13 14
The TreeSet class is the only class in the Collections Framework that implements the
NavigableSet interface, and the exam requires basic knowledge of the methods listed
previously.
Now let's discuss the details of using the various types of maps in the Collections
Framework.
Maps
The Map interface is the parent interface of the various maps in the Collections Framework.
Maps are unique in that they do not implement the Collection interface like all the other
collections classes. The elements in a map are pairs of data: a value and a key that maps to
that value. Think of a map as an array, except instead of integer indexes to access elements,
you use a key that can be any data type. Maps do not allow duplicate keys, but there is no
restriction on duplicate values.
Search WWH ::




Custom Search