Friday, February 12, 2016

StringExample7

package StringInJava;

public class StringExample7 {

/**
* String compare By equals() method By = = operator By compareTo() method
*/
public static void main(String[] args) {  
        /**
* The String  == operator compares the reference of the string
*/
String s5 = "Bhanu";
String s6 = "Bhanu";
String s7 = new String("Pratap");
// true (because both refer to same instance)
System.out.println(s5 == s6);
// false(because s7 refers to instance created in nonpool)
System.out.println(s5 == s7);

System.out.println(s6 == s7);

}

}

No comments:

Post a Comment