To compare 2 integer arrays using Java 8 Features -


this question has answer here:

is possible without external foreach iterate b. need identify common values in 2 arays using java 8

integer a[]={1,2,3,4}; integer b[]={9,8,2,3}; for(integer b1:b) {     stream.of(a).filter(a1 -> (a1.compareto(b1) ==0)).foreach(system.out::println);     } output: 2 3 

i suggest using sets if want common values (i.e. not taking duplicates account)

integer a[]={1,2,3,4}; integer b[]={9,8,2,3};  set<integer> aset = new hashset<>(arrays.aslist(a)); set<integer> bset = new hashset<>(arrays.aslist(b));  aset.retainall(bset); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -