Sitemap
Playwithjava

Playwithjava

I am a Software Techie having 10 yrs of experience in product development

find element from Java Stream

Aug 21, 2023

find**() method used to find element from the given Stream.

Optional<T> findAny()

Returns an Optional describing some element of the stream, or an empty Optional if the stream is empty.

Get Playwithjava’s stories in your inbox

Join Medium for free to get updates from this writer.

int []ab={11,13,15,17,181,19,20,21,23,24,25,26,27,28};



int num1=Arrays.stream(ab).findAny().getAsInt();

System.out.println("Find Any :: "+num1);


Result:

Find Any :: 11
Optional<T> findFirst()

Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.

int []ab={11,13,15,17,181,19,20,21,23,24,25,26,27,28};

int num2=Arrays.stream(ab).findFirst().getAsInt();

System.out.println("Find First :: "+num2);

--

--

Playwithjava
Playwithjava

Written by Playwithjava

I am a Software Techie having 10 yrs of experience in product development