We begin with the Arrays.stream method. We must import the java.util.Arrays class. Stream() returns specially-typed streams.
import java.util.Arrays;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Program {
public static void main(String[] args) {
// Use Arrays.stream to create an IntStream.
int[] array = { 10, 20, 30 };
IntStream stream = Arrays.stream(array);
// ... Call anyMatch on the IntStream.
boolean result = stream.anyMatch(number -> number >= 25);
System.out.println(result);
// Create a DoubleStream.
double[] array2 = { 1.2, 1.3, 1.4 };
DoubleStream stream2 = Arrays.stream(array2);
// ... Test the DoubleStream.
boolean result2 = stream2.anyMatch(number -> number >= 1.35);
System.out.println(result2);
// Create a Stream of Strings.
String[] array3 = {
"cat",
"dog",
"bird" };
Stream<String> stream3 = Arrays.stream(array3);
// ... Test the strings.
boolean result3 = stream3.anyMatch(value -> value.length() >= 4);
System.out.println(result3);
}
}
true
true
true