What is the differance between those two Strings in Java

Posted by user1816808 on Stack Overflow See other posts from Stack Overflow or by user1816808
Published on 2012-11-11T22:52:34Z Indexed on 2012/11/11 22:59 UTC
Read the original article Hit count: 110

Filed under:
|

why when we declare string in java we can't use == to compare this string and always will turn to false while if we initialize the string from the beginning it will be true . for example :

import java.util.Scanner;

public class MyString {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
    String s = input.nextLine();
            if(s=="Hello")
            system.out.println("Hello");

            String d = "Hello";
            if(d=="Hello")
            system.out.println("Hello");
}

}

I need an explanation please ??

© Stack Overflow or respective owner

Related posts about java

Related posts about string