Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

CollectionAPI: how to sort derived type elements (set type) other then collections sort method?

user-image
Question ajoutée par vivek vivek
Date de publication: 2013/07/09

your answer is one word "SortedSet" The SortedSet interface extends Set and declares the behavior of a set sorted in ascending order.
In addition to those methods defined by Set, the SortedSet interface declares the methods summarized in below Table: Several methods throw a NoSuchElementException when no items are contained in the invoking set.
A ClassCastException is thrown when an object is incompatible with the elements in a set.
A NullPointerException is thrown if an attempt is made to use a null object and null is not allowed in the set.
example : - public class SortedSetTest { public static void main(String[] args) { // Create the sorted set SortedSet set = new TreeSet(); // Add elements to the set set.add("b"); set.add("c"); set.add("a"); // Iterating over the elements in the set Iterator it = set.iterator(); while (it.hasNext()) { // Get element Object element = it.next(); System.out.println(element.toString()); } } } source: http://www.tutorialspoint.com/java/java_sortedset_interface.htm

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?