java - TreeMap used in SortedSet -


why can’t use other classes hashset,hashmap or other classes in place of treemap/treeset in sortedset interface?

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 hashset();         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: exception in thread "main" java.lang.error: unresolved compilation problem: type mismatch: cannot convert hashset sortedset

at sortedsetdemo.main(sortedsetdemo.java:10) 

hashset doesn't implement sortedset interface (a hashset not sorted). therefore can't assigned hashset instance sortedset variable.


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 -