문자열을 비교할때는 되도록 equals 을 사용하는 것이 좋다
package java_week2; public class StringTest { public static void main(String[] args) { String a = "한국"; String b = "한국"; StringBuffer c = new StringBuffer("한국"); StringBuffer d = new StringBuffer("한국"); if(a==b) System.out.println("a and b is same1"); if(a.equals(b)) System.out.println("a and b is same2"); if(c==d) System.out.println("c and d is same1"); if(c.toString().equals(d.toString())) System.out.println("c and d is same2"); } }
'2015 IT 웹 기반 개발자과정 > JAVA' 카테고리의 다른 글
JAVA 시간 입출력 (0) | 2015.10.28 |
---|---|
JAVA 로또 (0) | 2015.10.28 |
JAVA Bubble Sort (0) | 2015.10.27 |
JAVA 배열을 이용한 입력숫자 10개 정렬 (0) | 2015.10.26 |
JAVA 반복제어문 삼각형/마름모 만들기 (0) | 2015.10.26 |