-5

Please, consider the following code:

public static void main(String[] args) {
    String value="abc";
    value="";
    if(value==""){
        System.out.println("blank "+value);
    }
}

I do not understand why if(value=="") is returning as false.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
kiranB
  • 1
  • 1
  • 3
  • Read up on the difference between the equality operator `==` and the `equals` method. Would have also taken roughly 2s of googling or using the search here. – Ben May 23 '18 at 12:15
  • Funnily on my jdk9.0.4 your snippet does print `blank `. – Ole V.V. May 23 '18 at 12:22

1 Answers1

0

== tests for reference equality (whether they are the same object).

.equals() tests for value equality (whether they are logically "equal").

So make sure what you are testing and use the precise one