Java Reference
In-Depth Information
21. for(Character key : keys) {
22. System.out.print(key + “ “);
23. }
A breakdown of the previous statements follows:
Line 12 returns the least element greater than or equal to 'h' , which is the pair
('h', 104) .
Line 14 retrieves the tail of the map after the element 't' . Line 15 retrieves just the
keys from tailMap , and the for-each loop on line 16 displays these keys.
Line 20 is the keys from ascii in descending order, which are printed in the for-each
loop on line 21.
The output of the previous statements is
ceiling: h=104
t u v w x y z
z y x w v u t s r q p o n m l k j i h g f e d c b a
As you can see, a NavigableMap object provides many useful methods for navigating and
searching a map. The TreeMap class is the only class in the Collections Framework that
implements the NavigableMap interface.
Now that we have discussed generics and you've used them with the Collections
Framework, let's see how to introduce generics into your own code. The following section
discusses the details of writing and using generic types and methods.
Generic Types and Methods
Generic types are not exclusive to the Collections Framework. You can defi ne your own
classes, interfaces, and methods that use generic types. The exam requires a general
understanding of this technique, and this section examines the details of using generics in
your own classes, including a discussion on the following:
Generic classes
Generic interfaces
Generic methods
Bounded generic types
Generic wildcards
Let's start with generic classes.
Search WWH ::




Custom Search