Java Reference
In-Depth Information
System.out.println("Map = "+nm);
Listing 5-25 ' s System.out.println("Map = "+nm); method calls rely on
TreeMap 's toString() method to obtain the contents of a navigable map.
When you run this application, you observe the following output:
Map = {bluejay=12, robin=19, sparrow=83}
Ascending order of keys: bluejay robin sparrow
Descending order of keys: sparrow robin bluejay
First entry = bluejay=12
Last entry = sparrow=83
Entry < ostrich is bluejay=12
Entry > crow is robin=19
Poll first entry: bluejay=12
Map = {robin=19, sparrow=83}
Poll last entry: sparrow=83
Map = {robin=19}
TheCollectionsFrameworkwouldnotbecompletewithoutits Arrays and Collec-
tions utilityclasses.Eachclasssuppliesvariousclassmethodsthatimplementuseful
algorithms in the contexts of arrays and collections.
Following is a sampling of the Arrays class's array-oriented utility methods:
static <T> List<T> asList(T... a) returns a fixed-size list
backed by array a . (Changes to the returned list “write through” to the array.)
Forexample, List<String> birds = Arrays.asList("Robin",
"Oriole", "Bluejay"); converts the three-element array of String s
(recall that a variable sequence of arguments is implemented as an array) to a
List whose reference is assigned to birds .
static int binarySearch(int[] a, int key) searchesarray a
forentry key usingthebinarysearchalgorithm(explainedfollowingthislist).
undefined. This method returns the index of the search key, if it is contained
Search WWH ::

Custom Search