Java Character.hashCode()

Syntax

Character.hashCode() has the following syntax.

public int hashCode()

Example

In the following code shows how to use Character.hashCode() method.


/*w w  w  . j a va2  s  .  co  m*/
public class Main {

  public static void main(String[] args) {
    Character c1 = new Character('z');
    Character c2 = new Character('Z');

    int i1 = c1.hashCode();
    int i2 = c2.hashCode();

    String str1 = "Hashcode of " + c1 + " is " + i1;
    String str2 = "Hashcode of " + c2 + " is " + i2;

    System.out.println(str1);
    System.out.println(str2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable