mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-25 02:21:17 +07:00
19 lines
524 B
Java
19 lines
524 B
Java
// "Collapse loop with stream 'collect()'" "true-preview"
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class Test {
|
|
static String test(List<String> list) {
|
|
String sb = "";
|
|
if (!list.isEmpty()) {
|
|
sb = list.stream().filter(s -> !s.isEmpty()).map(s -> s.length() + "!").collect(Collectors.joining("\""));
|
|
}
|
|
return sb.trim();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println(test(Arrays.asList("abc", "", "xyz", "argh")));
|
|
}
|
|
} |