-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathStringDemo.java
More file actions
33 lines (28 loc) · 828 Bytes
/
StringDemo.java
File metadata and controls
33 lines (28 loc) · 828 Bytes
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
31
32
33
package lang;
/**
* @version 2018/2/5.
*/
public class StringDemo {
public static void main(String[] args) {
testIntern();
}
public static void testIntern() {
String s = new String("1");
String s2 = "1";
System.out.println(s == s2);
System.out.println(s.intern() == s2);
String s3 = new String("1") + new String("1");
s3.intern(); // 放入String常量池中了
String s4 = "11";
System.out.println(s3 == s4);
String s5 = new String("2") + new String("2");
String s6 = "22";
s3.intern();
System.out.println(s5 == s6);
}
public static void testSubString() {
String a = "hello";
System.out.println(a.substring(0, 5) == a);
System.out.println(a.substring(0, 4) == a);
}
}