I am looking for all type of string manipulation using java 8 Lambda expressions.
I first tried the trim()
method in simple String
list.
String s[] = {" S1","S2 EE ","EE S1 "};
List<String> ls = (List<String>) Arrays.asList(s);
ls.stream().map(String :: trim).collect(Collectors.toList());
System.out.println(ls.toString());
For this example, I was expecting to get [S1, S2 EE, EE S1]
,
but I got [ S1, S2 EE , EE S1 ]
.
collect()
produces a new List
, so you must assign that List
to your variable in order for it to contain the trimmed String
s :
ls = ls.stream().map(String :: trim).collect(Collectors.toList());
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