Learn Java for Android Development by Peter Späth & Jeff Friesen

Learn Java for Android Development by Peter Späth & Jeff Friesen

Author:Peter Späth & Jeff Friesen
Language: eng
Format: epub
ISBN: 9781484259436
Publisher: Apress


You need to be careful when designing classes that work with sorted sets. For example, the class must implement Comparable when you plan to store the class’s instances in a sorted set where these elements are sorted according to their natural ordering.

Exploring Navigable Sets

TreeSet is an example of a navigable set, which is a sorted set that can be iterated over in descending order as well as ascending order and which can report closest matches for given search targets. Navigable sets are described by the NavigableSet interface, whose generic type is NavigableSet<E>, which extends SortedSet. Have a look at the API documentation to learn about its methods.

Listing 9-5 demonstrates a navigable set based on a tree set.import java.util.Iterator;

import java.util.NavigableSet;

import java.util.TreeSet;

import java.util.Arrays;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.