What is the differance between those two Strings in Java
- by user1816808
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 ??