List of usage examples for java.util TreeMap TreeMap
public TreeMap(SortedMap<K, ? extends V> m)
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> db = new TreeMap<Integer, String>(Collections.reverseOrder()); db.put(1000, "1000"); db.put(1011, "1011"); db.put(1102, "1102"); db.put(2023, "2023"); db.put(2034, "2034"); System.out.println(db);//from ww w .jav a2 s . c om }
From source file:Main.java
public static void main(String[] args) { Map<Integer, String> map = new TreeMap<Integer, String>(new MyComparator()); map.put(2, "v"); map.put(3, "h"); map.put(4, "e"); map.put(1, "a"); System.out.println(map);//from w w w.j a va 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { Map<String, String> oldMap = new HashMap<String, String>(); oldMap.put("a", "1"); oldMap.put("A", "2"); Map<String, String> newMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); newMap.putAll(oldMap);/* www . j av a2 s . c om*/ String value = newMap.get("a"); System.out.println(value); }
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, String> sortedMap = new TreeMap<String, String>(yourMap); System.out.println(sortedMap); }
From source file:Main.java
public static void main(String[] args) { Comparator<String> keyComparator = Comparator.comparing(String::length) .thenComparing(String::compareToIgnoreCase); SortedMap<String, String> sMap = new TreeMap<>(keyComparator); sMap.put("CSS", "style"); sMap.put("HTML", "mark up"); sMap.put("Oracle", "database"); sMap.put("XML", "data"); SortedMap<String, String> subMap = sMap.subMap("CSS", "XML"); System.out.println(subMap);/*from ww w .ja v a2 s .c o m*/ // Get the first and last keys String firstKey = sMap.firstKey(); String lastKey = sMap.lastKey(); System.out.println("First Key: " + firstKey); System.out.println("Last key: " + lastKey); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("4", "four"); hm.put("3", "three"); hm.put("1", "one"); hm.put("2", "two"); Map<String, String> treeMap = new TreeMap<String, String>(hm); System.out.println(treeMap);/*w w w .java 2s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { HashMap<String, Double> map = new HashMap<String, Double>(); ValueComparator bvc = new ValueComparator(map); TreeMap<String, Double> sorted_map = new TreeMap<String, Double>(bvc); map.put("A", 9.0); map.put("B", 6.0); map.put("C", 7.0); map.put("D", 10.0); System.out.println("unsorted map: " + map); sorted_map.putAll(map);//from w w w . j av a 2 s.c o m System.out.println("results: " + sorted_map); }
From source file:List.java
public static void main(String args[]) throws Exception { Properties p = System.getProperties(); p.list(System.out);//www . j ava 2 s. c o m FileOutputStream fos = new FileOutputStream("sys.out"); p.store(fos, null); fos.close(); Map map = new TreeMap(p); System.out.println(map); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> db = new HashMap<Integer, String>(); db.put(1000, "1000"); db.put(1011, "1011"); db.put(1102, "1102"); db.put(2023, "2023"); db.put(2034, "2034"); TreeMap<Integer, String> db2 = new TreeMap<Integer, String>(db); System.out.println(db2);//from w w w.j a va2 s .c o m }
From source file:Main.java
public static void main(String args[]) { Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); SortedMap<String, Integer> nav = new TreeMap<String, Integer>(names); System.out.printf("Whole list:%n%s%n", nav); System.out.printf("First key: %s\tFirst entry: %s%n", nav.firstKey(), nav.firstEntry()); }