Wednesday, January 28, 2026
HomeLanguagesJavaCharset hashCode() method in Java with Examples

Charset hashCode() method in Java with Examples

The hashCode() method is a built-in method of the java.nio.charset returns the computed hashcode of any given charset.

Syntax:

public final int hashCode()

Parameters: The function does not accepts any parameter.

Return Value: The function returns the computed hashcode for the charset.

Below is the implementation of the above function:

Program 1:




// Java program to demonstrate
// the above function
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Gets the charset
        Charset first = Charset.forName("ISO-2022-CN");
  
        // Prints the hash-code
        System.out.println("The hash code for ISO-2022-CN is " + first.hashCode());
    }
}


Output:

The hash code for ISO-2022-CN is 1450311218

Program 2:




// Java program to demonstrate
// the above function
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Gets the charset
        Charset first = Charset.forName("x-windows-949");
  
        // Prints the hash-code
        System.out.println("The hash code for x-windows-949 is " + first.hashCode());
    }
}


Output:

The hash code for x-windows-949 is -1698752417

Reference: https://docs.oracle.com/javase/10/docs/api/java/nio/charset/Charset.html#hashCode()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6848 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6915 POSTS0 COMMENTS