java - Compare and match arrays with different sizes -


i have couple of arrays different sizes; say, array a , array b.

array 

[chery, chery, uindy, chery, chery]

array b 

[chery, uindy]

need check whether values present in array a available in array b or not. in above example, values in array available in array b. please out java code. thanks!

you can convert arrays list , use containsall method see if particular list contains elements described in list.

you better performance out of if sets instead.

example:

list<string> firstlist = arrays.aslist("chery", "chery", "unid", ...); list<string> secondlist = arrays.aslist("chery", "unid", ...);  system.out.println(secondlist.containsall(firstlist)); 

if performance of method in particular getting bit dodgy, consider converting lists sets instead:

set<string> firstset = new hashset<>(arrays.aslist("chery", "chery", "unid", ...)); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -