Code example for TreeSet

Methods: addAll

0
			tempArrayList.add(entry2.getKey());	  
		} 
		return tempArrayList;
	} 
	static <K,V extends Comparable<? super V>> SortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map) {
	    SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>(
	        new Comparator<Map.Entry<K,V>>() {
	            @Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) {
	                int res = e2.getValue().compareTo(e1.getValue());
	                return res != 0 ? res : 1; // Special fix to preserve items with equal values
	            } 
	        } 
	    ); 
	    sortedEntries.addAll(map.entrySet());
	    return sortedEntries;
	} 
 
}