일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- 네트워크
- IntelliJ
- Windows 10
- Source
- xargs
- ssh
- profile
- Quartz
- plugin
- grep
- find
- maVen
- netsh
- 줄바꿈 문자
- VirtualBox
- port
- import
- 단축키
- Mac
- JavaScript
- web.xml
- tomcat
- context
- vscode
- lsof
- Eclipse
- Windows
- GIT
- resource
- bash
- Today
- Total
develog
String 비교 본문
String str1 = "ABC";
String str2 = new String("ABC");
String str3 = "ABC";
System.out.println("str1 : " + str1);
System.out.println("str2 : " + str2);
System.out.println("str3 : " + str3);
System.out.println();
System.out.println("str1.toString() : " + str1.toString());
System.out.println("str2.toString() : " + str2.toString());
System.out.println("str3.toString() : " + str3.toString());
System.out.println();
System.out.println("str1.hashCode() : " + str1.hashCode());
System.out.println("str2.hashCode() : " + str2.hashCode());
System.out.println("str3.hashCode() : " + str3.hashCode());
System.out.println();
System.out.println("(str1 == str2) : " + (str1 == str2));
System.out.println("(str1 == str3) : " + (str1 == str3));
System.out.println("(str2 == str3) : " + (str2 == str3));
System.out.println();
System.out.println("str1.equals(str2) : " + str1.equals(str2));
System.out.println("str1.equals(str3) : " + str1.equals(str3));
System.out.println("str2.equals(str3) : " + str2.equals(str3));
System.out.println();
System.out.println("Long.toHexString(System.identityHashCode(str1)) : " + Long.toHexString(System.identityHashCode(str1)));
System.out.println("Long.toHexString(System.identityHashCode(str2)) : " + Long.toHexString(System.identityHashCode(str2)));
System.out.println("Long.toHexString(System.identityHashCode(str3)) : " + Long.toHexString(System.identityHashCode(str3)));
System.out.println();
// console
--------------------------------------------
str1 : ABC
str2 : ABC
str3 : ABC
str1.toString() : ABC
str2.toString() : ABC
str3.toString() : ABC
str1.hashCode() : 64578
str2.hashCode() : 64578
str3.hashCode() : 64578
(str1 == str2) : false
(str1 == str3) : true
(str2 == str3) : false
str1.equals(str2) : true
str1.equals(str3) : true
str2.equals(str3) : true
Long.toHexString(System.identityHashCode(str1)) : 1c78e57
Long.toHexString(System.identityHashCode(str2)) : 5224ee
Long.toHexString(System.identityHashCode(str3)) : 1c78e57
'Dev > Java' 카테고리의 다른 글
[java] 배열내 중복 체크 (0) | 2013.07.02 |
---|---|
generate file name (0) | 2013.07.02 |
Object.toString(), System.identityHashCode() (0) | 2013.07.02 |
진수 변환 (0) | 2013.07.02 |
log4sql (0) | 2013.06.28 |