Java 8 Stream: Find first element after element

Kihats :

I have this list ["z", "1", "3", "x", "y", "00", "x", "y", "4"] that I need to get the first Integer element after the String 00 in this case 4. I am using Java 8 streams but any other method is welcome. Here is my starter code

myList.stream()
      // Remove any non-Integer characters
      .filter((str) -> !"x".equals(str) && !"y".equals(str) && !"z".equals(str))
      .findFirst()
      .orElse("");

That starts me off by removing all non-Integer Strings but gives me 1. Now what I need is to get 4 which is the first element after 00. What should I add to the filter?

Lebecca :

Got from the comment.

 String result = myList.stream().skip(myList.indexOf("00") + 1)
        .filter((str) -> !"x".equals(str) && !"y".equals(str) && !"z".equals(str))
        .findFirst()
        .orElse("");

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=295355&siteId=1