-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringLearning.java
More file actions
91 lines (80 loc) · 1.98 KB
/
Copy pathStringLearning.java
File metadata and controls
91 lines (80 loc) · 1.98 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com;
import org.junit.Test;
/**
* @CreatedBy cx
* @CreatedTime 20180320
* @description string stringbuffer stringbuilder 及 对象引用类型
*/
public class StringLearning {
//Example1
//基本数据类型时(基本数据类型包 括 byte,int,short,char,float,double以及boolean),传递的只是该数据内容的一个副本
static void check(int a)
{
a++;
}
public static void main(String[]args)
{
int x=10;
check(x);
System.out.println("Example1.x="+x);
}
//Example2
//对象型数据类型的一种。一个方法传递对象型数据类型(包括String, StringBuffer,类对象引用,接口引用和数组等)
//传递的是该数据对象的某个引用变量(的副本)而不是对象内容本身
static void check(StringBuffer obj)
{
obj.append("JAVA");
}
@Test
public void test2()
{
StringBuffer x=new StringBuffer("Hello ");
check(x);
System.out.println("Example2.x="+x);
}
//Example3
//String类是final的,它的值一经创建就不可改变
static void check(String obj)
{
obj="JAVA";
}
static void check1(String obj)
{
obj = obj.substring(2,3);
}
@Test
public void test3()
{
String x="Hello ";
check(x);
System.out.println("Example3.x="+x);
check1(x);
System.out.println("Example3.x="+x);
}
//Example4
static void check(StringBuilder obj)
{
obj.append("JAVA");
}
@Test
public void test4()
{
StringBuilder x=new StringBuilder("Hello ");
check(x);
System.out.println("Example2.x="+x);
}
public int tttt(){
try {
Thread.activeCount();
}catch (Exception e){
return 0;
}finally {
//return 2;
}
return 1;
}
@Test
public void a(){
System.out.println(tttt());
}
}