< prev index next >

src/java.base/share/classes/java/lang/StringUTF16.java

Print this page

        

@@ -290,10 +290,24 @@
             }
         }
         return len1 - len2;
     }
 
+    /**
+     * hashCode consistent with {@link #compareToCI}
+     */
+    public static int hashCodeCI(byte[] value) {
+        int len = length(value);
+        int h = 0;
+        for (int k = 0; k < len; k++) {
+            char cu = (char) CharacterDataLatin1.instance.toUpperCase(getChar(value, k));
+            char cl = (char) CharacterDataLatin1.instance.toLowerCase(cu);
+            h = 31 * h + cl;
+        }
+        return h;
+    }
+
     public static int compareToCI_Latin1(byte[] value, byte[] other) {
         int len1 = length(value);
         int len2 = StringLatin1.length(other);
         int lim = Math.min(len1, len2);
         for (int k = 0; k < lim; k++) {
< prev index next >