File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @program JavaBooks
3+ * @description: String.Intern
4+ * @author: mf
5+ * @create: 2020/02/12 01:35
6+ */
7+
8+ package com .strings ;
9+
10+ /**
11+ * 使用 String.intern() 可以保证相同内容的字符串变量引用同一的内存对象。
12+ */
13+ public class SIntern {
14+ public static void main (String [] args ) {
15+ // 采用new String创建对象
16+ String s1 = new String ("aaa" );
17+ String s2 = new String ("aaa" );
18+ System .out .println (s1 == s2 ); // false
19+
20+ // 将s1的对象通过intern放到String Pool中
21+ String s3 = s1 .intern ();
22+ System .out .println (s1 .intern () == s3 ); // true
23+ System .out .println (s1 .intern () == s2 .intern ()); // true
24+ System .out .println (s3 == "aaa" ); // true
25+
26+
27+ // 如果是采用 "bbb" 这种使用双引号的形式创建字符串实例,会自动地将新建的对象放入 String Pool 中。
28+ String s4 = "bbb" ;
29+ String s5 = "bbb" ;
30+ System .out .println (s4 == s5 ); // true
31+ }
32+ }
Original file line number Diff line number Diff line change 3535 - [ 说说&和&&的区别] ( https://github.com/DreamCats/JavaBooks/blob/master/Basics/Java%E9%9D%A2%E8%AF%95%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md#%E8%AF%B4%E8%AF%B4%E5%92%8C%E7%9A%84%E5%8C%BA%E5%88%AB )
3636 - [ short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1; 有什么错?] ( https://github.com/DreamCats/JavaBooks/blob/master/Basics/Java%E9%9D%A2%E8%AF%95%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md#short-s1--1-s1--s1--1%E6%9C%89%E4%BB%80%E4%B9%88%E9%94%99-short-s1--1-s1--1-%E6%9C%89%E4%BB%80%E4%B9%88%E9%94%99 )
3737 - [ char 型变量中能不能存贮一个中文汉字?为什么?] ( https://github.com/DreamCats/JavaBooks/blob/master/Basics/Java%E9%9D%A2%E8%AF%95%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md#char-%E5%9E%8B%E5%8F%98%E9%87%8F%E4%B8%AD%E8%83%BD%E4%B8%8D%E8%83%BD%E5%AD%98%E8%B4%AE%E4%B8%80%E4%B8%AA%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%E4%B8%BA%E4%BB%80%E4%B9%88 )
38+ - [ 整形包装缓存池例子vlaueof] ( /Basics/src/com/pack/IntegerPackDemo.java )
3839- ** 构造器**
3940 - [ 构造器 Constructor 是否可被 override?] ( https://github.com/DreamCats/JavaBooks/blob/master/Basics/Java%E9%9D%A2%E8%AF%95%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md#%E6%9E%84%E9%80%A0%E5%99%A8-constructor-%E6%98%AF%E5%90%A6%E5%8F%AF%E8%A2%AB-override )
4041 - [ 构造方法有哪些特性?] ( https://github.com/DreamCats/JavaBooks/blob/master/Basics/Java%E9%9D%A2%E8%AF%95%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.md#%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E6%9C%89%E5%93%AA%E4%BA%9B%E7%89%B9%E6%80%A7 )
You can’t perform that action at this time.
0 commit comments