akki akki - 2 years ago 116
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download