0% found this document useful (0 votes)
4 views1 page

Java Stream AnyMatch Example

The document defines a TestDate class with a main method that uses Java 8 streams to check if the number 4 exists in an int array and the number 10 exists in a long array. It uses IntStream and LongStream with the anyMatch method to check if the predicate x == 4 or x == 10 is true for any element in the respective arrays, printing output based on the boolean results.

Uploaded by

ripudsudan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Java Stream AnyMatch Example

The document defines a TestDate class with a main method that uses Java 8 streams to check if the number 4 exists in an int array and the number 10 exists in a long array. It uses IntStream and LongStream with the anyMatch method to check if the predicate x == 4 or x == 10 is true for any element in the respective arrays, printing output based on the boolean results.

Uploaded by

ripudsudan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

package [Link].

core;

import [Link];
import [Link];

public class TestDate {

public static void main(String[] args) {

int[] number = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

//Java 8
boolean result = [Link](number).anyMatch(x -> x == 4);

if (result) {
[Link]("Hello 4");
} else {
[Link]("Where is number 4?");
}

long[] lNumber = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

boolean result2 = [Link](lNumber).anyMatch(x -> x == 10);

if (result2) {
[Link]("Hello 10");
} else {
[Link]("Where is number 10?");
}

You might also like