Kotlinlearncs.online LogoJava
Return to List

Solve: Remove Empty and Null from List (with assert)

Created By: Justin Maier
/ Version: 2024.11.0

Write a void method named cleanList that takes a List<String> as an argument and modifies the list to remove all elements that are either the empty String ("") or null.

Remember that you can use remove to remove elements from a List, though you should be careful that you do not remove elements from a List while you are iterating over it (with a for loop, for example).

You should assert that the List argument is not null.

void cleanList(List<String> list) {
return; // You may need to remove this starter code
}

Related Lessons

Stuck? You may find these lessons helpful: