关键字:忽略key大小写的map
有时候我们会需要一个不区分KEY大小写的MAP,
今天介绍一个apache.commons包里的类,
org.apache.commons.collections.map.CaseInsensitiveMap
例子:
public
static void main(String[] args) {
Map result
= new CaseInsensitiveMap();
result.put("aaa", "ok");
System.out.println(result.get("aaa"));
System.out.println(result.get("aAa"));
System.out.println(result.get("AAa"));
System.out.println(result.get("AAA"));
}
输出:
ok
ok
ok
ok
大家用到的时候记得。
HashMap是要区分大小写的
public static
void main(String[] args) {
Map result
= new HashMap();
result.put("aaa",
"ok");
System.out.println(result.get("aaa"));
System.out.println(result.get("aAa"));
System.out.println(result.get("AAa"));
System.out.println(result.get("AAA"));
}
ok
null
null
null