forked from CPU-Code/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringOnly.java
More file actions
65 lines (48 loc) · 1.38 KB
/
Copy pathStringOnly.java
File metadata and controls
65 lines (48 loc) · 1.38 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* User: cpucode
* Date: 2021/1/9
* Time: 10:17
* Github: https://github.com/CPU-Code
* CSDN: https://blog.csdn.net/qq_44226094
*/
package com.cpucode.java.string.table;
//String的基本使用:体现String的不可变性
public class StringOnly {
public static void main(String[] args) {
test1();
test2();
test3();
}
private static void test1(){
System.out.println("test1 开始 ");
//字面量定义的方式,存储在字符串常量池中
String s1 = "cpucpu";
String s2 = "codecode";
s2 = "cpucode";
//判断地址:
System.out.println(s1 == s2);
System.out.println(s1);
System.out.println(s2);
System.out.println("test1 结束");
System.out.println();
}
private static void test2(){
System.out.println("test2 开始 ");
String s1 = "cpu";
String s2 = "code";
s2 += "test";
System.out.println(s1);
System.out.println(s2);
System.out.println("test2 结束");
System.out.println();
}
private static void test3(){
System.out.println("test3 开始 ");
String s1 = "cauCode";
String s2 = s1.replace('a','p');
System.out.println(s1);
System.out.println(s2);
System.out.println("test3 结束");
System.out.println();
}
}