filterremoves items. If you do not want to delete elements, but simply change some of them, you can use ?:or if-else inside mapto selectively change the elements.
For example:
System.out.println(Stream.of("abc", "def", "ghi")
.map(a -> a.equals("def") ? "xyz" : a)
.collect(Collectors.toList()));
Or:
System.out.println(Stream.of("abc", "def", "ghi")
.map(a -> {
if (a.equals("def"))
return "xyz";
else
return a;
})
.collect(Collectors.toList()));
, def - xyz ( ), :
[abc, xyz, ghi]