* NewMain.java
*
* Created on December 14, 2010, 11:43 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Naveen
*/
public class NewMain {
/** Creates a new instance of NewMain */
public NewMain() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String s1="abc";
String s2="abc";
String s3=new String("abc");
Naveen Mirajkar December 15 at 12:16am
String s4=s1;
if(s1==s4) {
System.out.println("Hi0");
}
if(s1.equals(s4)) {
System.out.println("Hi00");
}
if(s1==s2) {
System.out.println("Hi");
}
if(s1==s3) {
System.out.println("Hello");
}
if(s1.equals(s2)) {
System.out.println("Hi1");
}
if(s1.equals(s3)) {
System.out.println("Hi2");
}
System.out.println(s1==s2); //true
System.out.println(s1==s3); //false diff object identity
System.out.println(s1.equals(s2)); //true
System.out.println(s1.equals(s3)); //true
System.out.println(System.identityHashCode(s1)); //they are
System.out.println(System.identityHashCode(s2)); //the same object
System.out.println(System.identityHashCode(s3)); //diff object
}
}
output
Hi0
Hi00
Hi
Hi1
Hi2
true
false
true
true
4072869
4072869
1671711
No comments:
Post a Comment