public class ArrayListTest {
public static void main(String[] args) {
ArrayList al=new ArrayList();
al.add("");
al.add("name");
al.add("");
al.add("");
al.add(4, "asd");
System.out.println(al);
}
}
o/p [, name, , , asd] desire O/p [name,asd]
You can use removeAll(Collection<?> c)
:
Removes all of this collection's elements that are also contained in the specified collection
al.removeAll(Arrays.asList(null,""));
This will remove all elements that are null
or equals to ""
in your List
.
Output :
[name, asd]
You can remove an object by value.
while(al.remove(""));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With