I need assistance with removing the element when the id is equal to a specific constant that I have. However when i run this code it does not remove the element with that constant. I am fairly new to java so I am a bit confused on why this does not remove the elemtn when id is equal to my constant. Any help would be greatly appreciated.
if (CollectionUtils.isNotEmpty(myResponse.getOrders())) {
List<Order> myList = new ArrayList<>();
myResponse.getOrders().stream()
.forEach(myResponse -> {
if (myResponse.getId() == Action.MY_CONSTANT) {
myList.remove(myResponse);
} else {
myList.add(setMyParams(myResponse));
}
});
return myList;
}
I have tried the remove() method inside of my conditional if statement but doesn't work.