0
for(int counter=0;counter<cells.size();counter++){
            System.out.println("The name typed is "+name);
            System.out.println("got to the loop");
            String storedName=cells.get(counter).toString();
            System.out.println("The cell name is "+storedName);


            if(storedName==name){
                System.out.println("Found it!");
                break;
            }else{

                System.out.println("Did not find it");
            }

        }

OUTPUT:

The name typed is JACK

got to the loop

The cell name is JACK

Did not find it

I don't understand why the if statement never returns true?

Johnny000
  • 2,058
  • 5
  • 30
  • 59
Thomas
  • 457
  • 2
  • 7
  • 12
  • 1
    `String` comparison in Java is done with `String#equals` method not `==`. `equals` will compare the content where as `==` will compare the memory reference of the two `String`s – MadProgrammer Dec 12 '13 at 04:25
  • Brain lapse, thank you very much. – Thomas Dec 12 '13 at 04:31

0 Answers0