See this example.
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("abc", "abc");
map.put("xyz", "xyz");
map.put("ABC", "ABC");
System.out.println(map);
}
Output
{ABC=ABC, abc=abc, xyz=xyz}
Map<String, String> map = new HashMap<String, String>();
map.put("abc", "abc");
map.put("xyz", "xyz");
map.put("ABC", "ABC");
System.out.println(map);
}
Output
{ABC=ABC, abc=abc, xyz=xyz}
But some times you may need to have a case insensitive map.
In such case you can use the java java.util.TreeMap, which let you to pass a Comparator to it's constructor.
See below example
public static void main(String[] args) {
Map<String, String> map = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
map.put("abc", "abc");
map.put("xyz", "xyz");
map.put("ABC", "ABC");
System.out.println(map);
}
Output
{abc=ABC, xyz=xyz}
Map<String, String> map = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
map.put("abc", "abc");
map.put("xyz", "xyz");
map.put("ABC", "ABC");
System.out.println(map);
}
Output
{abc=ABC, xyz=xyz}
Note:
Another option is to write your own class by extending the HashMap class and overriding the get() and put() methods.
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeletepython course institute in bangalore
python Course in bangalore
python training institute in bangalore
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeletepython interview questions and answers
python tutorials
python course institute in electronic city
Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteData Science Training in Indira nagar
Data Science training in marathahalli
Data Science Interview questions and answers
Data Science training in btm layout
Data Science Training in BTM Layout
Data science training in kalyan nagar