[Java beginner] == operator and equals method

■ == Operator: Operands (values and variables) to compare ■ equals method of object class: What to compare is an object

● The equals method is supposed to be overridden.

[Equals method of String class]

In the String type equals method, the String type character string is assigned to the char type array and checked character by character. That is, an instance of String type is judged as a character string.

(1) String a = new String("sample"); (2) String b = "sample"; (3) System.out.print(a==b); (4) System.out.print(a.equals(b));

[Explanation] (1) String type instance (2) String type literal (3) Execution result: false Reason: Because the reference is different (4) Execution result: true Reason: Because the character strings are being compared

Recommended Posts

[Java beginner] == operator and equals method
Difference between == operator and equals method
Study Java # 2 (\ mark and operator)
[Java] Difference between == and equals
[Java Silver] About equals method
[Java] HashCode and equals overrides
Java methods and method overloads
Differences between "beginner" Java and Kotlin
Java method
java (method)
== and equals
Difference between == operator and eqals method
[Java beginner] About abstraction and interface
java beginner 3
java beginner
Java method
Understanding equals and hashCode in Java
[Java] method
Java beginner design pattern (Factory Method pattern)
[Java] method
My thoughts on the equals method (Java)
Java starting from beginner, variables and types
Java Silver exam procedure and learning method
[Java] How to compare with equals method
[Beginner] Java method / class / external library [Note 23]
[Java] Collection and StringBuilder operation method comparison
[Java] TreeMap successor method and entrySet complexity
Java8 method reference
[Java] forEach method
Java Beginner Exercises
variable and method
Java and JavaScript
XXE and Java
java8 method reference
[Java] Random method
[Java] split method
Java Exercise "Beginner"
Build Java environment and output hello world [Beginner]
[Java SE 11 Silver] Arrays class method summary [Java beginner]
Basics of threads and Callable in Java [Beginner]
[Java beginner] println method without collection type specification
[Beginner] Java class field method / encapsulation (getter setter) [Note 25]
JAVA DB connection method
Getters and setters (Java)
[Java] Thread and Runnable
The comparison of enums is ==, and equals is good [Java]
Java learning 2 (learning calculation method)
Java true and false
Java learning memo (method)
[Java] String comparison and && and ||
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Java null coalescing operator
Java programming (class method)
[Java] About Objects.equals () and Review of String comparisons (== and equals)
Java --Serialization and Deserialization
[Java] Arguments and parameters
timedatectl and Java TimeZone
[Java] Branch and repeat