forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTest.java
More file actions
83 lines (64 loc) · 2.17 KB
/
StringTest.java
File metadata and controls
83 lines (64 loc) · 2.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
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
package zzzTest;
import Standard.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by nibnait on 2016/10/11.
*/
public class StringTest {
public static void main(String[] args) {
testSubString();
}
private static void testSplit() {
String str = "253";
String[] split = str.split(",");
System.out.println(split.length);
System.out.println(split);
}
public static void test02(){
System.out.println(StringUtils.isNotBlank(null));
System.out.println(StringUtils.isNotBlank(""));
System.out.println(StringUtils.isNotBlank(" "));
}
public void testEquals(){
String a = "ab";
String b = "a"+"b";
System.out.println(a.equals(b)); //true
System.out.println("------------xxx-------------");
String str2 = "a";
String str3 = "b";
List<String> stringList = new ArrayList<>();
stringList.add(str2);
stringList.add(str3);
System.out.println(String.join(";", stringList));
}
private static void testSubString() {
List<Long> ids = new ArrayList<>();
ids.add(1l);
ids.add(2l);
ids.add(3l);
System.out.println(ids.lastIndexOf(']'));
String str = ids.toString();
System.out.println(str.substring(1, str.length()-1));
System.out.println(str);
}
/**
* 检查字符串是否包含某个字符串
*/
public void checkStringContains() {
String haystack = "Programming in Java";
String needle1 = "Java";
String needle2 = "Pascal";
int index1 = haystack.indexOf(needle1);
int index2 = haystack.indexOf(needle2);
System.out.println(index1+" "+index2);
if (index1 != -1)
System.out.println("The string contains the substring " + needle1);
else
System.out.println("The string does not contain the substring " + needle1);
if (index2 != -1)
System.out.println("The string contains the substring " + needle2);
else
System.out.println("The string does not contain the substring " + needle2);
}
}