2015 IT 웹 기반 개발자과정/JAVA

JAVA string과 string buffer 의 차이점

한여름밤의코딩 2015. 10. 27. 17:50
문자열을 비교할때는 되도록 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");
		

	}

}