jdk/src/share/classes/java/lang/Character.java
changeset 3943 11abf5578222
parent 3942 685e04a98396
child 5506 202f599c92aa
child 5610 fd2427610c7f
--- a/jdk/src/share/classes/java/lang/Character.java	Tue Sep 22 18:30:58 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Character.java	Tue Sep 22 18:30:58 2009 -0700
@@ -4964,7 +4964,25 @@
      * @since   1.2
      */
     public int compareTo(Character anotherCharacter) {
-        return this.value - anotherCharacter.value;
+        return compare(this.value, anotherCharacter.value);
+    }
+
+    /**
+     * Compares two {@code char} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Character.valueOf(x).compareTo(Character.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code char} to compare
+     * @param  y the second {@code char} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(char x, char y) {
+        return x - y;
     }
 
     /**