forked from coderbruis/JavaSourceCodeLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTest.java
More file actions
49 lines (43 loc) · 1.17 KB
/
StringTest.java
File metadata and controls
49 lines (43 loc) · 1.17 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
package com.learnjava.string;
import org.junit.Test;
/**
* @author LuoHaiYang
*/
public class StringTest {
@Test
public void testSplitWithSplit() {
String splitStr1 = "what,is,,,,split";
String[] strs1 = splitStr1.split(",");
for (String s : strs1) {
System.out.println(s);
}
System.out.println(strs1.length);
}
@Test
public void testSplitWithOutSplit() {
String splitStr1 = "what,is,,,,";
String[] strs1 = splitStr1.split(",");
for (String s : strs1) {
System.out.println(s);
}
System.out.println(strs1.length);
}
@Test
public void testSplitLimit() {
String splitStr1 = "what,is,,,,";
String[] strs1 = splitStr1.split(",", -1);
for (String s : strs1) {
System.out.println(s);
}
System.out.println(strs1.length);
}
@Test
public void testSplitLimitGreaterThanZero() {
String splitStr1 = "what,is,,,,";
String[] strs1 = splitStr1.split(",", 3);
for (String s : strs1) {
System.out.println(s);
}
System.out.println(strs1.length);
}
}