Java equals() Method | Tutorial
Tutorial -- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Java Tutorial
Java Tutorial Java Introduction Java Development Environment Setup Java Basic Syntax Java Comments Java Objects and Classes Java Basic Data Types Java Variable Types Java Variable Naming Rules Java Modifier Types Java Operators Java Loop Structures β for, while and doβ¦while Java Conditional Statements β ifβ¦else Java switch case Statement Java Number & Math Class Java Character Class Java String Class Java StringBuffer and StringBuilder Class Java Arrays Java Date and Time Java Regular Expressions Java Methods Java Constructors Java Stream, File, and IO Java Scanner Class Java Exception Handling
Java Object-Oriented
Java Inheritance Java Override/Overload Java Polymorphism Java Abstraction Java Encapsulation Java Interfaces Java Enums Java Package Java Reflection
Java Advanced Tutorial
Java Data Structures Java Collections Framework Java ArrayList Java LinkedList Java HashSet Java HashMap Java Iterator Java Object Java NIO Files Java Generics Java Serialization Java Networking Java Sending Email Java Multithreading Java Applet Basics Java Documentation Comments Java Examples Java 8 New Features Java MySQL Connection Java 9 New Features Java Quiz Java Common Libraries
Java equals() Method
The equals() method is used to determine whether a Number object is equal to the method's parameter.
Syntax
public boolean equals(Object o)
Parameters
o -- Any object.
Return Value
If the Number object is not null, and its type and numerical value are both equal to the method's parameter, it returns True; otherwise, it returns False.
Double and Float objects have some additional conditions. You can refer to the API manual: JDK 1.6.
Example
Example
public class Test{
public static void main(String args[]){
Integer x = 5;
Integer y = 10;
Integer z = 5;
Short a = 5;
System.out.println(x.equals(y));
System.out.println(x.equals(z));
System.out.println(x.equals(a));
}
}
Compile the above program, the output result is:
false
true
false
Click to Share Notes
Write notes...
Image URL
Image Description
Share Notes
- Nickname (Required)
- Email (Required)
- Reference URL
YouTip