ValueRange equals() method in Java with Examples
Last Updated :
29 Jan, 2020
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:
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
LocalDateTime l1
= LocalDateTime
.parse( "2020-10-06T08:21:14" );
LocalDateTime l2
= LocalDateTime
.parse( "2019-12-26T08:21:14" );
ValueRange vR1
= l1.range(ChronoField.DAY_OF_MONTH);
ValueRange vR2
= l2.range(ChronoField.DAY_OF_MONTH);
boolean response = vR1.equals(vR2);
System.out.println( "Both ValueRange are equal: "
+ response);
}
}
|
Output:
Both ValueRange are equal: true
Program 2:
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
ValueRange vRange = ValueRange.of( 1111 , 66666 );
ValueRange OtherVRange = ValueRange.of( 111 , 66666 );
boolean response = vRange.equals(OtherVRange);
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
Share your thoughts in the comments
Please Login to comment...