String 선언 차이 (literal vs new)
- new로 선언하면 java heap memory에 개별 객체가 생성됨
String strA = new String("Hello World");
- literal로 선언하면 String Constant Pool에 생성된 객체를 참조함
String strB = "Hello World";
equals() 메소드
String strA = "Hello World";
String strB = "Hello World";
String strC = new String("Hello World");
System.out.println(strA.equals(strB)); // true
System.out.println(strA.equals(strC)); // true
== 연산자
String strA = "Hello World";
String strB = "Hello World";
String strC = new String("Hello World");
System.out.println(strA == strB); // true
System.out.println(strA == strC)); // false