Below is my list of String.
["sunday", "monday", "tuesday", "wednesday", "thurs", "fri", "satur"]
I want to do remove "day" from the elements, if it is ending with "day".
Expected Output in the list:
["sun", "mon", "tues", "wednes", "thurs", "fri", "satur"]
How to do this using Lambda?
I have tried the below code, but was unable to assign the value to the list:
daysList.stream().forEach(s -> {
if (s.endsWith("day")) {
s = s.substring(0, s.indexOf("day"));
}
});
day
at the end with nothing, i.e. applyString#replaceAll("day$", "")
to all elements. Just an idea how to get rid of the condition. If you can't write the changed elements back to the list (I don't know that API that well yet but "forEach" indicates it is not possible) you could collect them into a new list. – Charmer