package com.gotion.datatrace.utils;
import java.util.HashSet;
import java.util.Set;
/**
* @author 2022041215
*/
public class StringSetUtils {
/**
* 校验字符串是否为空
*
* @param s 传入的字符串
* @return Boolean
*/
public static boolean isEmpty(String s) {
return s == null || s.length() < 1;
}
/**
* 将字符串处理成集合
* [["abc"],["def"]] => [abc,def]
*
* @param s 入参,要处理的字符串
* @return set集合
*/
public static Set<String> transformString2Set(String s) {
String[] splits = s.replaceAll("\"", "")
.replaceAll("\\[", "")
.replaceAll("]", "")
.split(",");
Set<String> set = new HashSet<>();
for (String split : splits) {
if (!isEmpty(split)) {
set.add(split);
}
}
return set;
}
}
自定义简单字符串处理类
最新推荐文章于 2024-06-13 08:37:22 发布