In Java, I have an ArrayList of Strings like:
[,Hi, ,How,are,you]
I want to remove the null and empty elements, how to change it so it is l
public static void listRemove() {
List list = Arrays.asList("", "Hi", "", "How", "are", "you");
List result = new ArrayList();
for (String str : list) {
if (str != null && !str.isEmpty()) {
result.add(str);
}
}
System.out.println(result);
}