-1

This is the code I have right now and can't figure out why this while loop isnt ending when there is a period entered.

while (emailTxt!="."){
  emailTxt = "";
  emailTxt = scanner.nextLine();
  totalText.add(emailTxt);
}
Ars
  • 41
  • 2

2 Answers2

2

emailTxt is a String. A String in Java is considered an Object. You want to use the Object.equals().

So

while(!(emailTxt.equals("."))

0

You should use equals() to compare two string.

while (!".".equals(emailTxt)) {
    // ...
}
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35