mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-24 17:51:09 +07:00
28 lines
710 B
Java
28 lines
710 B
Java
// "Replace Stream API chain with loop" "true-preview"
|
|
|
|
import java.util.Objects;
|
|
import java.util.function.DoubleSupplier;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
|
|
public class Main {
|
|
public void test(String... list) {
|
|
DoubleSupplier s = () -> {
|
|
long sum = 0;
|
|
long count = 0;
|
|
for (String string : list) {
|
|
if (string != null) {
|
|
sum += string.length();
|
|
count++;
|
|
}
|
|
}
|
|
return count > 0 ? (double) sum / count : 0.0;
|
|
};
|
|
System.out.println(s.getAsDouble());
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs");
|
|
}
|
|
}
|