I’m trying to detect a particular string value in an external txt file. In this case, I am trying to detect %%.
public void read(){
while(x.hasNext()){
String a = x.next();
System.out.println(a);
if(a == "%%"){
System.out.println("Found the end");
}
else{
System.out.println("No end");
}
}
}
It is reading x correctly because it prints out the words from the file, but it says “No end” after every word, even the “%%”. I’m sure I am making some dumb mistake somewhere, I just can’t find it. x looks like this: apple orange %% grapes. Any help with this would be appreciated.
Try
That should get rid of any excess whitespace at the end of the string as well as ensure a good comparison!