0

I have a program which can recognize specific words from a file .txt

The problem is when find a word I send it to a method like "value" and I question:

if (value == "specificword") {...}

this question is always false. I have made many debugs and I'm sure both are the same word (without a space or tab or enter) so: Is it possible this be a problem with the text format?

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
alex
  • 323
  • 1
  • 2
  • 16

1 Answers1

1

You need to use equals method for string comparision. Change this

if (value == "specificword") {...}

to

if (value.equals("specificword")) {...}

equals method compares the string contents while == checks for object equality. Read this related post for more info:

Java String.equals versus ==

Community
  • 1
  • 1
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136