1

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 getPlayingSongList() is matching.

I am using com.annimon:stream library in android.

2 Answers 2

2

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()) {
   System.out.println(c.getAsInt());
}

>>>> 2
Sign up to request clarification or add additional context in comments.

Comments

2

using Akah's suggestion, for android, below code works well.

Optional<Integer> c = Stream.range(0, getPlayingSongList().size()).filter(n -> songList.get(position).getId().equals(getPlayingSongList().get(n).getId())).findFirst();

            if (c.isPresent()) {
                Log.i("get index", c.get()+" ok");
            }

Thanks a lot.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.