I have a List with the following elements.
List<String> numbers = new ArrayList<String>();
numbers.add("1");
numbers.add("2");
numbers.add("3");
How do I get a subset of the List without say "1"? Is there a simpler function which will work against a List of any type.
You could use Guava to create a filtered
Collectionview:That’s a live view of the original
List, so it’s very efficient to create but might not be efficient to use depending on how you need to use it and how small the filtered collection is compared to the original. You can copy it to a new list if that will work better:The simplest way to create a copy list containing all elements except the one you don’t want is to use a simple
forloop:If you want to modify the original list instead,
numbers.removeAllis what you want (as mentioned by @Robin Green).