문제

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?

도움이 되었습니까?

해결책

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 ==

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top