how can i change this method to lambda without any loops or if's?
public Collection<String> test (Collection<String> strings) {
ArrayList<String> arrayListOfStrings = new ArrayList();
for(String str : strings) {
if(str.length() >= 10) {
String s = str.substring(str.length() / 2);
if(s.charAt(0) >= 'a') {
arrayListOfStrings.add(s.toUpperCase());
}
}
}
return arrayListOfStrings;
}
i've tried it this way, someones got another or better solution?:
public Collection<String> test (Collection<String> strings) {
ArrayList<String> arrayListOfStrings = new ArrayList<String>();
Stream<String> myStream = strings.stream()
.filter(str -> str.length() >= 10)
.map(str -> str.substring(str.length()/2))
.filter(str -> str.charAt(0) >= 'a');
myStream.forEach(str -> arrayListOfStrings.add(str.toUpperCase()));
return arrayListOfStrings ;
}
thx for help :)