'Find the next higher value in ArrayList - Java

I have an ArrayList of comments levels. Main comments have level 1, sub-comments have level 2 or 3:

1, 1, 2, 3, 3, 2, 1

After the first comment with level 2 - I need to find out if there will be another comment with level 2 within the same comments tree.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source