Wednesday, June 17, 2026
HomeLanguagesJavaLevel hashCode() method in Java with Examples

Level hashCode() method in Java with Examples

The hashCode() method of java.util.logging.Level is used to get hashcode of the level object. The hashcode is always the same if the object doesn’t change. Hashcode is a unique code generated by the JVM at the time of object creation. We can use hashcode to perform some operation on hashing related algorithms like a hashtable, hashmap, etc. We can search for an object with that unique code.

Syntax:

public int hashCode()

Parameters: This method accepts nothing.

Return: This method returns an integer value which represents hashCode value for this level.

Below programs illustrate hashCode() method:
Program 1:




// Java program to illustrate hashCode() method
  
import java.util.logging.Level;
import java.util.logging.Logger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                        Object.class.getName())
                  .getParent();
  
        // Get level of logger
        Level level
            = logger.getLevel();
  
        // get hashCode
        int val = level.hashCode();
  
        // print result
        System.out.println("HashCode = "
                           + val);
    }
}


Output:

HashCode = 800

Program 2:




// Java program to illustrate hashCode() method
  
import java.util.logging.Level;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Get level of logger
        Level level
            = Level.parse("SEVERE");
  
        // get hash Code
        int value = level.hashCode();
  
        // print result
        System.out.println("Hash Code = "
                           + value);
    }
}


Output:

Hash Code = 1000

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Level.html#hashCode()

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS