java - Can we use other class in SortedSet interface -


the below code gives sorted elements & sortedset can't instantiated interface & hence treeset used instantiate class & question why treeset used instead of other classes because sortedset gives sorted order element & hence treeset used?

import java.util.hashset; import java.util.iterator; import java.util.sortedset; import java.util.treeset;  public class sortedsetdemo  {     public static void main(string[] args)      {            sortedset s=new treeset();         s.add("akash");         s.add("prakash");         s.add("bhushan");         s.add("chetan");         system.out.println("sortedset:");         iterator itr=s.iterator();         while(itr.hasnext())         {             system.out.println(itr.next());         }     } } 

output: sortedset: akash bhushan chetan prakash

as can see here http://docs.oracle.com/javase/7/docs/api/java/util/sortedset.html treeset 1 of classes implements sortedset interface. practice work against interface implementation-independent. of course can take implementation of sortedset


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -