How to remove empty results after splitting with regex in Java?

前端 未结 7 1598
臣服心动
臣服心动 2021-01-17 16:02

I want to find all numbers from a given string (all numbers are mixed with letters but are separated by space).I try to split the input String but when check the result arra

7条回答
  •  情歌与酒
    2021-01-17 16:32

    If you are using java 8, you can do it in 1 statement like this:

    String[] array = Arrays.asList(s1.split("[,]")).stream().filter(str -> !str.isEmpty()).collect(Collectors.toList()).toArray(new String[0]);
    

提交回复
热议问题