Issue
I am trying to compare a String from a file, with a given String, in Java:
BufferedReader reader = new BufferedReader(new FileReader(file));
String currentLine = reader.readLine(); //currentLine={25769803781}
if (currentLine.equals("cut"));
System.out.println(currentLine);
It prints {25769803781} which is not equal to "cut". What's wrong here.
Solution
You are ending the if statement prematurely. Try it like this:
if (currentLine.equals("cut")) {
System.out.println(currentLine);
}
Answered By - Sam
Answer Checked By - David Marino (JavaFixing Volunteer)