I have following String Array
tmp = [null, null, null, Mars, Saturn, Mars] coming after doing the operation -
allSig[d3].split(\" \"); where
This is a very old question but this Java 8+ solution might be useful to someone:
public static String[] removeElements(String[] allElements) {
return Arrays.stream(allElements)
.filter(Objects::nonNull)
.collect(Collectors.toArray());
}
or if you, like me, are a fan of readable code and don't want static methods to get in your way, you can simplify this even further using static imports:
public static String[] removeElements(String[] allElements) {
return stream(allElements).filter(Objects::nonNull).collect(toArray());
}