IGotManyQuestions
IGotManyQuestions

Reputation: 29

Checking to see if an array has any strings in an array list

ArrayList<String>  mylist = new ArrayList<String>(); 
build2 = "";
  String[] source = file2.split(" ");
  for(int i = 0; i < source.length; i++){
    int offset = mylist.indexOf(source[i]);

    if(Arrays.asList(source).equals(mylist)){
    build2 += (char)(65 + offset);
    }

  }

  System.out.println("\nYour decrypted message is: \n" + build2);

This is a encryption and decryption project. Right now the string array mylist contains a bunch of unicodes for poker cards. And my array source contains poker cards and number.

I would like to check, if there are poker cards in the array then display-

build2 += (char)(65 + offset); (which converts certain poker cards to letters)

My full code is here - https://repl.it/@MatthewZeman/DecryptionCode https://repl.it/@MatthewZeman/EncryptionCode

input -

🃁 36 🂱 36 🂡 

output -

ABC

Upvotes: 0

Views: 65

Answers (1)

Nils K
Nils K

Reputation: 44

I think you are looking for List.containsAll().

List.equals() only returns true if both Lists contain the same elements in the same order.

If you want to check that all elements are present in both lists:

if(Arrays.asList(source).containsAll(mylist)){
   build2 += (char)(65 + offset);
}

Upvotes: 2

Related Questions