adarsh :
I have a class FilterEvent with following attributes
filterId
filterValue
filterType
Suppose i have a list of FilterEvent
called filterEvents
.
I need to remove filterId from each of the object of the list .
I tried in following way
Set<FilterEvent> filterEvents = preparation.getFilterEvents();
filterEvents.stream().map(f->f.setFilterId(null))
to set filterId field set to null . This will not work since my filterId field is of type int .
I need either filterId set to null or need to remove the field itself.
Eran :
map
won't work, since it's an intermediate operation, so it won't be executed unless it is followed by some terminal operation.
Use forEach
:
Set<FilterEvent> filterEvents = preparation.getFilterEvents();
filterEvents.forEach(f->f.setFilterId(null));
However, if setFilterId
expects an int
, you can't pass null
. You'll have to set it to some other value (0?).