Printing Common Values of Two Arrays

arrays, java

Solution

Most likely you want to:

Change:

if(fibList.get(i) == primeList.get(j))

To:

if(fibList.get(i).equals(primeList.get(j)))

Problem

I am working on a java project and need to print common values between two arrays. I have printed both arrays in their sorted order before hand and they both look good (containing all values they should). However, when I follow the simplest of algorithms (see below) I do not find all the common values even though I can manually see in the print out of the two arrays without comparison that there should be more values printed after executing the below: ``` for(int i=0; i<fibList.size(); i++) { for(int j=0; j<primeList.size(); j++) { if(fibList.get(i) == primeList.get(j)) { System.out.print(" " + fibList.get(i)); break; } } } ``` Please let me know what you think. Hopefully this is just a simple error.

Original source