akki akki - 10 months ago 54
Android Question

How to get particular index for any data from list using Java Stream?

Here is a code to check if particular string is matched or not from List

if (Stream.of(getPlayingSongList()).filter(o -> o.getId().equals(songList.get(position).getId())).findFirst().isPresent()) {
ToastMethod.show(getActivity(), "Song is already in queue", true);

I want to know, which index from
is matching.

I am using
library in android.


What about using IntStream.range ?

Since I don't have you whole code, I'm just putting a dummy example :

String[] myArray = { "a", "b", "c", "d" };
OptionalInt c = IntStream.range(0, myArray.length).filter(n -> "c".equals(myArray[n])).findFirst();

if (c.isPresent()) {

>>>> 2