Level hashCode() method in Java with Examples
Last Updated :
14 Oct, 2019
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:
import java.util.logging.Level;
import java.util.logging.Logger;
public class GFG {
public static void main(String[] args)
{
Logger logger
= Logger.getLogger(
Object. class .getName())
.getParent();
Level level
= logger.getLevel();
int val = level.hashCode();
System.out.println( "HashCode = "
+ val);
}
}
|
Program 2:
import java.util.logging.Level;
public class GFG {
public static void main(String[] args)
{
Level level
= Level.parse( "SEVERE" );
int value = level.hashCode();
System.out.println( "Hash Code = "
+ value);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Level.html#hashCode()
Share your thoughts in the comments
Please Login to comment...