Case insensitive string as HashMap key
<p>I would like to use case insensitive string as a HashMap key for the following reasons.</p>

<ul>
<li>During initialization program creates HashMap with user defined String</li>
<li>While processing an event (network traffic in my case) I might received String in a different case but I should be able to locate the  from HashMap ignoring the case I received from traffic.</li>
</ul>

<p>I've followed this approach</p>

<p>CaseInsensitiveString.java</p>

<pre><code>    public final class CaseInsensitiveString {
            private String s;

            public CaseInsensitiveString(String s) {
                            if (s == null)
                            throw new NullPointerException();
                            this.s = s;
            }

            public boolean equals(Object o) {
                            return o instanceof CaseInsensitiveString &amp;&amp;
                            ((CaseInsensitiveString)o).s.equalsIgnoreCase(s);
            }

            private volatile int hashCode = 0;

            public int hashCode() {
                            if (hashCode == 0)
                            hashCode = s.toUpperCase().hashCode();

                            return hashCode;
            }

            public String toString() {
                            return s;
            }
    }
</code></pre>

<p>LookupCode.java</p>

<pre><code>    node = nodeMap.get(new CaseInsensitiveString(stringFromEvent.toString()));
</code></pre>

<p>Because of this, I'm creating a new object of CaseInsensitiveString for every event. So, it might hit performance. </p>

<p>Is there any other way to solve this issue? </p>
