I have searched for this but it's in other languages like Python or R (?). I have lists inside a list and I would like to remove the empty list. For example:
[ [abc,def], [ghi], [], [], [jkl, mno]]
I would like:
[ [abc,def], [ghi], [jkl, mno]]
How do I remove empty list from a list? Thanks!
Short answer: You can remove all empty lists from a list of lists by using the list comprehension statement [x for x in list if x] to filter the list.
You could try this as well:
list.removeIf(p -> p.isEmpty());
You could use:
list.removeAll(Collections.singleton(new ArrayList<>()));
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