Thursday, September 18, 2025
HomeLanguagesJavaValueRange hashCode() method in Java with Examples

ValueRange hashCode() method in Java with Examples

The hashCode() method of ValueRange class is used to get the hashCode value for this ValueRange. It returns an integer value which is the hashCode value for this instance of the ValueRange.

Syntax:

public int hashCode()

Parameters:
This method accepts nothing.

Return value:
This method returns a suitable hash code.

Below programs illustrate the ValueRange.hashCode() method:
Program 1:




// Java program to demonstrate
// ValueRange.hashCode() method
  
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create LocalDateTime
        LocalDateTime l1
            = LocalDateTime
                  .parse("2018-02-06T19:21:12");
  
        // Get ValueRange object
        ValueRange vR
            = l1.range(ChronoField.DAY_OF_MONTH);
  
        // apply hashCode()
        int code = vR.hashCode();
  
        // print results
        System.out.println("hashCode: "
                           + code);
    }
}


Output:

hashCode: 1900573

Program 2:




// Java program to demonstrate
// ValueRange.hashCode() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1111, 66666);
  
        // apply hashCode()
        int code = vRange.hashCode();
  
        // print results
        System.out.println("hashCode: "
                           + code);
    }
}


Output:

hashCode: 3932210

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#hashCode()

RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6663 POSTS0 COMMENTS
Nicole Veronica
11835 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7053 POSTS0 COMMENTS
Thapelo Manthata
6736 POSTS0 COMMENTS
Umr Jansen
6742 POSTS0 COMMENTS