Vote Up 0 Vote Down

Store value without considering case of String key in a Set

We would like to know how to store value without considering case of String key in a Set.

answer


Vote Up 0 Vote Down
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
// www .javascrapbook.com/getanswer
public class Main {
    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);
        String value = newMap.get("a");
        System.out.println(value);
    }

}
flag | link

your answer

Who Are You?

Have an account already? Login before answering!