I have a list of String
List<String> strings = new ArrayList<>(Arrays.asList("C", "C++", "Java"));
And now I want to create another list, which would contain all elements of strings that contain "C". So I believe that the condition would look like this:
(String a) -> a.contains("C");
What is the fastest and most clear way to do that?
strings.stream().filter(t -> t.contains("C")).collect(Collectors.toList())strings.removeIf(a -> !a.contains("C"))(Note that this modifies thestringsList itself.)