Open In App

ValueRange equals() method in Java with Examples

Last Updated : 29 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The equals() method of ValueRange class is used to check if this ValueRange is equal to another ValueRange or not where another ValueRange is passed as a parameter to the method. The comparison is based on the four values, minimum, largest minimum, smallest maximum, and maximum.

Syntax:

public boolean equals(Object obj)

Parameters: This method accepts obj which is the object to check.

Return value: This method returns true if this is equal to the other range.

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




// Java program to demonstrate
// ValueRange.equals() 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("2020-10-06T08:21:14");
        LocalDateTime l2
            = LocalDateTime
                  .parse("2019-12-26T08:21:14");
  
        // Get ValueRange object
        ValueRange vR1
            = l1.range(ChronoField.DAY_OF_MONTH);
        ValueRange vR2
            = l2.range(ChronoField.DAY_OF_MONTH);
  
        // apply equals()
        boolean response = vR1.equals(vR2);
  
        // print results
        System.out.println("Both ValueRange are equal: "
                           + response);
    }
}


Output:

Both ValueRange are equal: true

Program 2:




// Java program to demonstrate
// ValueRange.equals() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange objects
        ValueRange vRange = ValueRange.of(1111, 66666);
        ValueRange OtherVRange = ValueRange.of(111, 66666);
  
        // apply equals()
        boolean response = vRange.equals(OtherVRange);
  
        // print results
        System.out.println("Both ValueRange are equal: "
                           + response);
    }
}


Output:

Both ValueRange are equal: false

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads