Sort TreeMap by key using order CASE_INSENSITIVE_ORDER

java

Solution

You can pass the case insensitive order comparator as the argument of one of TreeMap's constructors:

TreeMap<String, String> treemap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);

Problem

How can I sort a `TreeMap<String, String>` in `CASE_INSENSITIVE_ORDER` based on key. Currently, by default, it is sorted like: A B C D a b c d I want it to be like: a A b B c C d D

Original source