-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringDemo.java
More file actions
53 lines (43 loc) · 1.58 KB
/
StringDemo.java
File metadata and controls
53 lines (43 loc) · 1.58 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
/**
* String,StringBuffer,StringBuilder
*/
public class StringDemo {
public static void main(String[] args) {
char[] helloArray = {'r', 'u', 'n', 'o', 'o', 'b'};
String str = new String(helloArray);
System.out.println(str);
str = "Hello World!";
System.out.println(str.length());
String str1 = "test";
String str2 = "Test";
System.out.println(str1.equalsIgnoreCase(str2));
System.out.println(str1.toUpperCase().concat(str2));
StringBuffer stringBuffer = new StringBuffer("Test1");
int capacity = stringBuffer.capacity();
System.out.println(capacity);
stringBuffer.append("Hello");
stringBuffer.append("world");
stringBuffer.delete(1, 2);
capacity = stringBuffer.capacity();
System.out.println(capacity);
System.out.println(stringBuffer);
System.out.println(stringBuffer.reverse());
StringBuilder sb = new StringBuilder("Test1");
int size = sb.capacity();
System.out.println(size);
//System.exit(0);
String aa = new String("ab");
String bb = new String("ab");
String aaa = "ab";
String bbb = "ab";
System.out.println(aa.hashCode()+"/"+bb.hashCode()+"/"+aaa.hashCode()+"/"+bbb.hashCode());
if (aa == bb)
System.out.println("aa==bb");
if (aaa == bbb)
System.out.println("aaa==bbb");
if (aa.equals(bb))
System.out.println("aa equals bb");
if (aaa.equals(bbb))
System.out.println("aaa equals bbb");
}
}