I have a List
declared as:
List<String[]> arrayList = new ArrayList<>();
This List
contains multiple arrays of String
s.
I need to check if a String[]
which I have is contained in this ArrayList<String[]>
.
I am currently iterating through the ArrayList
and comparing each String[]
with the one I am searching for:
for(String[] array: arrayList){
if(Arrays.equals(array, myStringArray)){
return true;
}
}
return false;
Is there any better way to check if an ArrayList<String[]>
contains a specific String[]
?
Array.equals()
is the most efficient method afaik. That method alone meant for the purpose and optimized as less as it is in the current state of implementation which is a single for
loop.
Just go for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With