1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
List<String> transactionTypeList = StringUtils.isBlank(transactionType) || "all".equals(transactionType) ? Collections.emptyList() :
Splitter.on(",").omitEmptyStrings().trimResults()
.splitToList(transactionType);
// 将字符串转为集合
List<String> stringList = Splitter.on("-").omitEmptyStrings().trimResults()
.splitToList("1-2-3-4- 5- 6 "); // [1, 2, 3, 4, 5, 6]
Map<String, String> stringStringMap = Splitter.on(",").omitEmptyStrings().trimResults().withKeyValueSeparator("=")
.split("1=A, 2=B, 3=C "); // {1=A, 2=B, 3=C}
// 正则分隔字符串
Splitter.onPattern("[.|,]").omitEmptyStrings().trimResults()
.splitToList(" aa.dd, ,ff,,. "); // [aa, dd, ff]
/**
* 小写驼峰逗号字符串 转 小写下划线List集合 sort,createTime,id 转 [sort,create_time,id]
*/
List<String> strings = Splitter.on(",").omitEmptyStrings().trimResults()
.splitToList(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "sort,createTime,id"));
|