@Slf4j
public class StrParser {
public static List<String> strToStrList(String messages) {
List<String> rtList = Lists.newArrayList();
if (StringUtils.isEmpty(messages)) {
return rtList;
}
rtList = Splitter.on(",").splitToList(messages);
return rtList;
}
public static List<Long> strToNumList(String messages) {
if (StringUtils.isEmpty(messages)) {
return null;
}
List<Long> idList = Lists.newArrayList();
try {
idList = Splitter.on(",").trimResults().splitToList(messages).stream()
.map(s -> Long.parseLong(s.trim())).collect(
Collectors.toList());
} catch (Exception e) {
log.error("用户编号格式传递错误 ids {}", messages);
}
return idList;
}
// public static void main(String[] args) {
// System.out.println(strToStrList(null));
// System.out.println(strToStrList(""));
// System.out.println(strToStrList(",ss,df").size());
// System.out.println(strToNumList("111,222"));
// }
}
使用方式: