user3474606
user3474606

Reputation: 515

Problems using contains() method for arraylist

I am trying to check if an arraylist B contains a string from arrayA with this, but it doesn't work:

String match = arrayA[i];
if (! B.contains(match)) {
    outputFile.print(match);
}

Is this because I used the contains() method incorrectly?
Can we put the name of the variable in the contains() method like contains(match) here?
Or do we have to put a string in the contains(), like contains("name")?

Upvotes: 0

Views: 137

Answers (1)

Christian Kullmann
Christian Kullmann

Reputation: 578

In

  if (! B.contains(match))

you check, if B does NOT contain match. Apart from that, the approach is valid.

Upvotes: 1

Related Questions