- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LocalTime equals() method in Java
The equality of two LocalTime objects can be determined using the equals() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be compared. Also it returns true if both the LocalTime objects are equal and false otherwise.
A program that demonstrates this is given as follows
Example
import java.time.*; public class Main { public static void main(String[] args) { LocalTime lt1 = LocalTime.parse("23:15:30"); LocalTime lt2 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime lt1 is: " + lt1); System.out.println("The LocalTime lt2 is: " + lt2); boolean flag = lt1.equals(lt2); if(flag) System.out.println("
Both LocalTime objects are equal"); else System.out.println("
Both LocalTime objects are not equal"); } }
output
The LocalTime lt1 is: 23:15:30 The LocalTime lt2 is: 23:15:30 Both LocalTime objects are equal
Now let us understand the above program.
The two LocalTime objects are displayed. It is checked if the LocalTime objects are equal using the equals() method. The returned value of the method is displayed using an if statement. A code snippet that demonstrates this is as follows:
LocalTime lt1 = LocalTime.parse("23:15:30"); LocalTime lt2 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime lt1 is: " + lt1); System.out.println("The LocalTime lt2 is: " + lt2); boolean flag = lt1.equals(lt2); if(flag) System.out.println("
Both LocalTime objects are equal"); else System.out.println("
Both LocalTime objects are not equal");
- Related Articles
- LocalTime compareTo() method in Java
- LocalTime ofNanoOfDay() method in Java
- LocalTime getMinute() method in Java
- LocalTime get() method in Java
- LocalTime isAfter() method in Java
- LocalTime isBefore() method in Java
- LocalTime getHour() method in Java
- LocalTime getNano() method in Java
- LocalTime getSecond() method in Java
- LocalTime hashCode() method in Java
- LocalTime ofSecondOfDay() method in Java
- LocalTime format() method in Java
- LocalTime from() method in Java
- LocalTime range() method in Java
- LocalTime until() Method in Java

Advertisements