Character.hashCode() in Java with examples
Last Updated :
06 Dec, 2018
Java.lang.Character.hashCode() is a built-in method in Java which returns a hash code for this Character. The returned hash code is equal to the result of invoking charValue().
Syntax:
public int hashCode()
This function does not accepts any parameter.
Return Value: This method returns a hash code value for this Character.
Below programs illustrate the Java.lang.Character.hashCode() function:
Program 1:
import java.lang.*;
public class Gfg {
public static void main(String[] args)
{
char ch = 'B' ;
Character c = Character.valueOf(ch);
int i = c.hashCode();
System.out.println( "Hashcode of " + ch + " is " + i);
}
}
|
Output:
Hashcode of B is 66
Program 2:
import java.lang.*;
public class Gfg {
public static void main(String[] args)
{
char ch = '6' ;
Character c = Character.valueOf(ch);
int i = c.hashCode();
System.out.println( "Hashcode of " + ch + " is " + i);
}
}
|
Output:
Hashcode of 6 is 54
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...