Skip to content

Commit 6804164

Browse files
committed
feat:[使用 StringUtils.split 的坑](https://www.wdbyte.com/java/stringutils_split.html)
1 parent 3092e34 commit 6804164

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<module>tool-java-apache-httpclient</module>
1616
<module>tool-java-object-pool</module>
1717
<module>tool-java-jackson</module>
18+
<module>tool-java-apache-common</module>
1819
</modules>
1920
<name>parent-modules</name>
2021
<description>Parent for all java modules</description>

tool-java-apache-common/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>parent-modules</artifactId>
7+
<groupId>com.wdbyte</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>tool-java-apache-common</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.wdbyte.string;
2+
3+
import java.util.Arrays;
4+
5+
import org.apache.commons.lang3.StringUtils;
6+
7+
/**
8+
* apache common lang StringUtils test
9+
* @author niulang
10+
* @date 2022/11/01
11+
*/
12+
public class StringUtilsTest {
13+
14+
public static void testA() {
15+
String str = "aabbccdd";
16+
String[] resultArray = StringUtils.split(str, "bc");
17+
for (String s : resultArray) {
18+
System.out.println(s);
19+
}
20+
}
21+
22+
public static void testB() {
23+
String str = "abc";
24+
String[] resultArray = StringUtils.split(str, "ac");
25+
for (String s : resultArray) {
26+
System.out.println(s);
27+
}
28+
}
29+
30+
public static void testC() {
31+
String str = "abcd";
32+
String[] resultArray = StringUtils.split(str, "ac");
33+
for (String s : resultArray) {
34+
System.out.println(s);
35+
}
36+
}
37+
38+
public static void testD() {
39+
String str = "aabbccdd";
40+
String[] resultArray = StringUtils.splitByWholeSeparator(str, "bc");
41+
for (String s : resultArray) {
42+
System.out.println(s);
43+
}
44+
}
45+
46+
public static void testE() {
47+
//String str = "aabbccdd";
48+
//Iterable<String> iterable = Splitter.on("bc")
49+
// .omitEmptyStrings() // 忽略空值
50+
// .trimResults() // 过滤结果中的空白
51+
// .split(str);
52+
//iterable.forEach(System.out::println);
53+
}
54+
55+
public static void testF() {
56+
String str = "aabbccdd";
57+
String[] res = str.split("bc");
58+
for (String re : res) {
59+
System.out.println(re);
60+
}
61+
62+
}
63+
64+
public static void testG() {
65+
String str = ",a,,b,";
66+
String[] splitArr = str.split(",");
67+
Arrays.stream(splitArr).forEach(System.out::println);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)