String Concept for == or equals and StringBuffer and intern
SOURCE : StringConcept.javapublic class StringConcept { public static void main(String[] args) { String s1="sandy"; String s2="sandy"; String s3="sandy".intern(); String s4= new String("sandy"); String s5= new String("sandy").intern(); StringBuffer sb = new StringBuffer("sandy"); StringBuffer sb1 = new StringBuffer("sandy"); if(s1==s2){System.out.println("s1 and s2 ");} if(s1==s3){System.out.println("s1 and s3 ");} if(s1==s4){System.out.println("s1 and s4 ");} if(s1==s5){System.out.println("s1 and s5 ");} //if(s1==sb){System.out.println("s1 and sb");} if(s1.equals(sb)){System.out.println("s1 and sb");} if(s1.equals(sb1)){System.out.println("s1 and sb");} }}INPUTOUTPUTs1 and s2 s1 and s3 s1 and s5

0 comments :
Post a Comment