805 OCPJP 6 Questions 788 SCJP 5 questions 650 OCPJWCD 5 questions 600 OCAJP 7 questions 610 OCPJP 7 questions 510 Upgrade to OCPJP 7 questions 900 Java J2EE Qns

Tutorials

SCJP : NavigableSet

public interface NavigableSet
extends SortedSet
A SortedSet extended with navigation methods reporting closest matches for given search targets. Methods lower, floor, ceiling, and higher return elements respectively less than, less than or equal, greater than or equal, and greater than a given element, returning null if there is no such element.


A NavigableSet may be accessed and traversed in either ascending or descending order
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;




public class Test {

public static void main(String... args) {
               
		
		 List lst = new ArrayList();
		 lst.add(34);
		 lst.add(6);
		 lst.add(2);
		 lst.add(8);
	     lst.add(7);
	     lst.add(10);
	     lst.add(2);
	        
	        NavigableSet  nvset = new TreeSet(lst);
	       Iterator iterator = (Iterator)nvset.iterator();
	        while (iterator.hasNext()){
	             System.out.print(iterator.next() + " ");
	        }

	      
	}
}
					
The output:
2 6 7 8 10 34 			
					
scjp 1.5 | scjp 1.6 | scwcd 1.5
Java Certifications
www.javacertifications.net