[자바 Object 메서드] 74. Equals

김건우's avatar
Feb 18, 2025
[자바 Object 메서드] 74. Equals
💡
문자열은 equals 로 검증해라 !
package ex17; public class HA03 { public static void main(String[] args) { // 가니까 값이 있다. int n1 = 1; int n2 = 1; System.out.println(n1 == n2); // 가니까 주소가 있다. 근데 참조주소가 같다. String s1 = "A"; String s2 = "A"; System.out.println(s1 == s2); s2 = s2 + "B"; System.out.println(s1 == s2); // 최종 목적지를 검사해보자. (값을) - equlas ( (1)두번 검사 == 통과 못하면 -> (2)최종값) String s3 = new String("A"); String s4 = new String("A"); System.out.println(s3.hashCode()); System.out.println(s4.hashCode()); } }
notion image
Share article

gunwoo