Removing unfilled values or null values from array of String in Java

前端 未结 7 1287
醉话见心
醉话见心 2020-12-16 02:22

I have following String Array tmp = [null, null, null, Mars, Saturn, Mars] coming after doing the operation - allSig[d3].split(\" \"); where

7条回答
  •  抹茶落季
    2020-12-16 02:43

    Simplest Solution :

     public static String[] clean(final String[] v) {
        List list = new ArrayList(Arrays.asList(v));
        list.removeAll(Collections.singleton(null));
        return list.toArray(new String[list.size()]);
    }
    

提交回复
热议问题