Case-insensitive Collection
TreeHashMap
@Test public void testTreeMap(){ Map<String, String> map = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); map.put("aBc", "test1"); map.put("dEf", "test2"); Assert.assertEquals("test1", map.get("abc")); Assert.assertEquals("test2", map.get("dEf")); }
Spring
public class CaseInsensitiveMap extends TreeMap<String, Object> { private static final long serialVersionUID = 1L; public CaseInsensitiveMap(){ super(String.CASE_INSENSITIVE_ORDER); } }
<util:map id="restDisplayMap" map-class="com.supermicro.ssm.common.CaseInsensitiveMap"> <entry key="xxx1" value="uuuu1"></entry> <entry key="xxx2" value="uuuu2"></entry> </util:map>
TreeSet
@Test public void testTreeSet(){ Set<String> s = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); s.add("aBc"); s.add("deF"); Assert.assertTrue(s.contains("abc")); Assert.assertTrue(s.contains("def")); Assert.assertFalse(s.contains("abcedf")); }