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
  • 66,028
  • 11
  • 91
  • 129
alex
  • 313
  • 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
  • 66,028
  • 11
  • 91
  • 129
  • :P tanks I can't belive it n___n – alex Sep 22 '13 at 00:53
  • @alex Glad to help. If my answer helped just accept it by clicking on the tick mark left to my answer. Accepting an answer helps other facing the same problem/challenge. – Juned Ahsan Sep 22 '13 at 00:56