Below is my list of String.
["sunday", "monday", "tuesday", "wednesday", "fri", "satur"]
I want to do remove "day" from the elements if it is ending with "day". How to do this in Lambda ?
Expected Output in the list:
["sun", "mon", "tues", "wednes", "fri", "satur"]
I have tried the below code, but unable to assign the value to the list
daysList.stream().forEach(s -> { if(s.endsWith("day")) {
s = s.substring(0, s.indexOf("day"));
}});
Can anyone please help me on this ?
Most of the answers here make use of a Stream, but you should not be using a Stream at all:
daysList.replaceAll(s -> s.replaceFirst("day$", ""));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With