functional programming - Check order of two elements in Java-8-Stream -


i want check order of 2 elements in java-8-stream. have iterator-solution:

public static boolean isbefore (a a1,                                 a2,                                 stream<a> as) {     iterator<a> = as.iterator ();     while (it.hasnext ()) {         a = it.next ();         if (a == a1) {             return true;         } else if (a == a2) {             return false;         }     }     throw new illegalargumentexception (         a1 + " , + " a2 + " arent elements of stream!"); } 

is there solution without iterators in more functional/non imperative style?

it this

as.filter (a -> (a==a1) || (a==a2)).findfirst () 

and check if result a1 or a2 or empty. i'm sorry don't give full solution, it's hard if smart phone


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -