Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to check if List<String[]> contains a String[] [duplicate]

I have a List declared as:

List<String[]> arrayList = new ArrayList<>();

This List contains multiple arrays of Strings.

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[]?

like image 308
Swadeesh Avatar asked Aug 21 '14 07:08

Swadeesh


1 Answers

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.

like image 105
Suresh Atta Avatar answered Sep 28 '22 03:09

Suresh Atta