forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTest.java
More file actions
21 lines (19 loc) · 708 Bytes
/
StringTest.java
File metadata and controls
21 lines (19 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package JavaBasic;
/**
* @Author MaoTian
* @Classname StringTest
* @Description TODO
* @Date 上午9:39 2019/8/15
* @Version 1.0
* @Created by mao<tianmao818@qq.com>
*/
public class StringTest {
public static void main(String args[]) {
String s1 = new StringBuilder().append("String").append("Test").toString();
System.out.println(s1.intern() == s1);
//当调用 intern 方法时,如果常量池中已经该字符串,则返回池中的字符串;
// 否则将此字符串添加到常量池中,并返回字符串的引用。
String s2 = new StringBuilder().append("ja").append("va").toString();
System.out.println(s2.intern() == s2);
}
}