it evaluates to true so the second line will run. The third line will run unconditioned, your output will be
true false In the way you just created your string, a literal "test" will be created in the string constant pool and an Object on the heap, if you would have initiated it like String t = "test"; only the literal in the constant pool would have been created. The string object on the heap acts like any other object. The literal in the pool is not being garbage collected but in change any string with a literal value of "test" will refere to it and a new constant won't be created. From here i guess many pros and cons would rise. I am curious to see what other people think about it also. On Jul 9, 11:41 pm, Fatih Ergin <[email protected]> wrote: > String t = new String (“test”); > > If (“test”.equals(t)) > System.out.println (“true”); > System.out.println (“false”); > > Is this a True statement ? What are the Pros and Cons using Strings > like the example above? > Thanks.. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
