LocalTime equals() method in Java with Examples Last Updated : 03 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The equals() method of a LocalTime class is used to compare this LocalTime object to the LocalTime passed as parameter and returns true when objects are equal else false. The comparison between both LocalTimes is based on timeline position of the local times within a day. The value to be returned by this method is determined as follows: if both LocalTimes are equal, then true is returned if both instances are not equal, then false is returned Syntax: public int equals(Object obj) Parameters: This method accepts a single parameter object which is the other LocalTime to be compared, and it should not be null. Return Value: This method returns the int value and returned value is determined as follows: if both LocalTimes are equal, then true is returned if both instances are not equal, then false is returned Below programs illustrate the equals() method: Program 1: When both objects are equal. Java // Java program to demonstrate // LocalTime.equals() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime Objects LocalTime time1 = LocalTime.parse("13:08:00"); LocalTime time2 = LocalTime.parse("13:08:00"); // print Values System.out.println("LocalTime1: " + time1); System.out.println("LocalTime2: " + time2); // compare both LocalTimes boolean value = time1.equals(time2); // print results System.out.println("Are both LocalTimes are equal: " + value); } } Output: LocalTime1: 13:08 LocalTime2: 13:08 Are both LocalTimes are equal: true Program 2: When both objects are not equal. Java // Java program to demonstrate // LocalTime.equals() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime Objects LocalTime time1 = LocalTime.parse("03:18:23"); LocalTime time2 = LocalTime.parse("13:08:20"); // print values System.out.println("LocalTime1: " + time1); System.out.println("LocalTime2: " + time2); // compare both LocalTimes boolean value = time1.equals(time2); // print results System.out.println("Are both LocalTimes are equal: " + value); } } Output: LocalTime1: 03:18:23 LocalTime2: 13:08:20 Are both LocalTimes are equal: false Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#equals(java.lang.Object) Comment More infoAdvertise with us Next Article Java Long equals() method with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-LocalTime Practice Tags : Java Similar Reads LocalDateTime equals() method in Java with Examples The equals() method of LocalDateTime class in Java checks if this date-time is equal to another date-time. This other date-time is passed as the parameter. This method returns a boolean value showing the same. Syntax: public boolean equals(Object date2) Parameter: This method accepts a parameter dat 2 min read List equals() Method in Java with Examples The List equals() method is used to compare two lists. It compares the lists as, both lists should have the same size, and all corresponding pairs of elements in the two lists are equal. Implementation:Java// Java code to show the implementation of // addAll method in list interface import java.util 2 min read Level equals() method in Java with Examples The equals() method of java.util.logging.Level is used to check if this level object is equals to passed object or not.If both objects are equals then method will return true else false. Syntax: public boolean equals(Object ox) Parameters: This method accepts an object ox which is the reference obje 2 min read Java Long equals() method with Examples The java.lang.Long.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object. It returns false if both the objects are not same. In all ot 3 min read Java Long equals() method with Examples The java.lang.Long.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object. It returns false if both the objects are not same. In all ot 3 min read Java Long equals() method with Examples The java.lang.Long.equals() is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object. It returns false if both the objects are not same. In all ot 3 min read Like