Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One approach is to create a custom subclass of the Apache Commons <a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/AbstractHashedMap.html"><code>AbstractHashedMap</code></a> class, overriding the <code>hash</code> and <code>isEqualKeys</code> methods to perform case insensitive hashing and comparison of keys. (Note - I've never tried this myself ...)</p> <p>This avoids the overhead of creating new objects each time you need to do a map lookup or update. And the common <code>Map</code> operations should O(1) ... just like a regular <code>HashMap</code>.</p> <p>And if you are prepared to accept the implementation choices they have made, the Apache Commons <a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/map/CaseInsensitiveMap.html"><code>CaseInsensitiveMap</code></a> does the work of customizing / specializing <code>AbstractHashedMap</code> for you.</p> <hr> <p>But if O(logN) <code>get</code> and <code>put</code> operations are acceptable, a <code>TreeMap</code> with a case insensitive string comparator is an option; e.g. using <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#CASE_INSENSITIVE_ORDER"><code>String.CASE_INSENSITIVE_ORDER</code></a>.</p> <p>And if you don't mind creating a new temporary String object each time you do a <code>put</code> or <code>get</code>, then Vishal's answer is just fine. (Though, I note that you wouldn't be preserving the original case of the keys if you did that ...)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload