String Concept for == or equals and StringBuffer and intern

String Concept for == or equals and StringBuffer and intern
SOURCE : StringConcept.java


public 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");}

}

}


INPUT




OUTPUT

s1 and s2
s1 and s3
s1 and s5







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment