0
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
6
  • 1
    What you wrote is very confusing, I read it three times and didn't get what you want... Can you at least provide an example of input and your desired output ? Commented Jan 17, 2019 at 15:06
  • @SchiduLuca does that help? It is a little bit hard for me to explain Commented Jan 17, 2019 at 15:10
  • What is your current output? Describe problems that you ran into. Commented Jan 17, 2019 at 15:11
  • My current output doesn't display anything @CrazySabbath. Right now I want it to only display a letter if there are poker cards in the array that are also in the arraylist Commented Jan 17, 2019 at 15:13
  • @IGotManyQuestions seems that if(Arrays.asList(source).equals(mylist)){ will never equal true, that is why you don't get any output as build2 will never be mutated Commented Jan 17, 2019 at 15:14

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Im sorry I have never worked with .containsAll before, do you mind showing me how to apply it to my code specifically?
I added an example but I think there is more stuff you have to improve in your code to make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.