新增方法
This commit is contained in:
parent
684fe584f3
commit
ca99fe345b
@ -8,6 +8,7 @@ import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
|||||||
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
||||||
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -307,4 +308,42 @@ public class WStringUtil {
|
|||||||
return subStrSB.toString();
|
return subStrSB.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* string对象转数组
|
||||||
|
*
|
||||||
|
* @param strObj stirng 对象
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 字符串数组
|
||||||
|
*/
|
||||||
|
public static String[] strObjToArray(Object strObj, String separator) {
|
||||||
|
if (strObj == null || separator == null) {
|
||||||
|
throw new RuntimeException("参数不能为空!");
|
||||||
|
}
|
||||||
|
if (!(strObj instanceof String)) {
|
||||||
|
throw new RuntimeException("第一个参数只能是String类型");
|
||||||
|
}
|
||||||
|
return strObj.toString().split(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串列表转字符串
|
||||||
|
*
|
||||||
|
* @param strings 字符串列表
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String listToStr(List<String> strings, String separator) {
|
||||||
|
if (strings == null || strings.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(String str : strings) {
|
||||||
|
if(sb.length() > 0) {
|
||||||
|
sb.append(separator);
|
||||||
|
}
|
||||||
|
sb.append(str);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user