And don't fall for the so-common mistake of comparing with ==, which compares only the internal pointers, i.e., checks if it's EXACLY the same object in memory.
On Fri, Jul 10, 2009 at 8:17 AM, Ewald Ertl <[email protected]> wrote: > > Hi, > > On Jul 9, 10: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 > In java terms you need an else statement to separate the condition. > the if-keyword is in lower letters. > > @Pros and Cons: > Depends on what you like to do. > The version with "test".equals() is in my opinion the better way, > because if prevents > a possible NullPointerException when t is not set, like in t.equals > ("test"). > > Ewald > > > > -- Diogo Sales Oliveira --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
