将字符串 12,45,89 转成List
/**
* 将字符串 12,45,89 转成List<Long>
*/
@Test
public void test2() {
String str = "fghj,48,drftyguhji,,";
List<Long> ids = Stream
.of(str.split(","))
//过滤非数字的字符串
.filter(s -> Pattern.matches("^[1-9]\\d*|0$", s))
.map(Long::valueOf)
.collect(Collectors.toList());
System.out.println(ids);
//[48]
}
标签:48,stream,45,List,89,具体,使用,字符串
From: https://www.cnblogs.com/lyn8100/p/16602091.html