Home Forums Job & Work Life 자바 초급 질문 드려요 EditDeleteReply 2021-12-0519:46:39 #3653743 외노자 208.***.145.251 679 String a = “hello”; String b = new String(“hello”); 이 두 문단의 차이가 뭔가요? String은 primitive case인데 왜 new를 쓰나요? Love1 Hate1 List Write EditDeleteReply 그르게 174.***.195.96 2021-12-0520:44:19 자바 스트링은 빌트인이고 자체로 가비지 컬렉터도 있는데 c++도 아니고 왜 그르나 그건 아닐쎄. EditDeleteReply 0000 68.***.3.209 2021-12-0520:45:57 https://stackoverflow.com/questions/334518/java-strings-string-s-new-stringsilly EditDeleteReply …. 66.***.124.6 2021-12-0521:21:18 Is String a primitive type? https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html String a = “string”; String b = “string”; String c = new String(“string”); String d = new String(“string”); System.out.println((a==b) + “, ” + (c==d) + “, ” + (b==c)); // –> true, false, false. 위의 stackoverflow에 설명되어 있네요. EditDeleteReply 123 108.***.4.205 2021-12-0523:00:47 대부분의 랭귀지에서 스트링은 immutable string result = “aaa” 이렇게 해도 내부적으로 새로 생성되는 것이고 result = “bbb” 로 바꾸는 문법을 써도 교체가 아니고 aaa는 사라지고 bbb 를 새로 생성함. 다만 편하게 프로그래밍 하게 해주기 위해서 제공하는 편의사항임 EditDeleteReply A 73.***.59.2 2021-12-0603:56:35 걍 a를 쓰면댐 EditDeleteReply 졸업자 205.***.210.104 2022-01-0709:57:24 String 도 클래스이여서 원래는 new operator 을 써야하는데 자바에서 스트링을 많이 쓰다보니 new 없이도 String a = “Hello”; 만 써도 되게 되어있어요 Name * Password * Email I agree to the terms of service Cancel Comment