Yes, string is immutable also.
If you do like this:

String s1 = "c";
        String s2 = s1;
        System.out.println(s2==s1);
        s1 = s1+"b";
        System.out.println(s2==s1);

The output will be:
true
false

Khang Vo

On Sep 22, 4:07 am, Victor Lutin <umg.victor.lu...@gmail.com> wrote:
> Because you are comparing references and no values themselves.
>
> System.out.println(x1.equals(x2));
>
> will print true, because you are comparing variable contents :).
>
> On Mon, Sep 21, 2009 at 3:01 PM, ANUJ KUMAR <kumar.anuj...@gmail.com> wrote:
> > class test
> > {
>
> > public static void main(String args[])
> > {
> >  String x1 = "abc";
> > String x2 = "ab";
> > x2 = x2 + "c";
> >   System.out.println(x1==x2);
>
> > }
> > }
> > why does it print false?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to