Java TreeMap merge case insensitive String key values via String.CASE_INSENSITIVE_ORDER

Description

Java TreeMap merge case insensitive String key values via String.CASE_INSENSITIVE_ORDER

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    Map<String, String> oldMap = new HashMap<String, String>();
    oldMap.put("Java", "1");
    oldMap.put("SQL", "2");
    oldMap.put("sql", "3");
    oldMap.put("Javascript", "4");
    oldMap.put("java", "5");

    Map<String, String> newMap = new TreeMap<String, String>();
    newMap.putAll(oldMap);/*  w w w.  j  a  v a2s. com*/
    
    System.out.println(newMap);
    
    newMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    newMap.putAll(oldMap);
    
    System.out.println(newMap);
  }

}



PreviousNext

Related