Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

when a string is empty but not null nor "" + JTable (sorta)

807597Jan 7 2005 — edited Jan 8 2005
Hi
Im wondering what is the standard way to test if a string is empty. For example the string returned from the table is from a blank cell, the string is 'empty'
        aString = (String)table.getValueAt(x,y);   
        aString.trim();
        
        if  (aString.equals(null)) { System.out.println("tis null"); }
        if  (aString.equals("")) { System.out.println("tis empty"); }
       
        if  (aString == null) { System.out.println("tis null =="); }
        if  (aString == "") { System.out.println("tis empty =="); }
Looking at the api for string it seems the best method is to use length(). A string with 1 character is length 2. Is this safe or may i get caught out doing this ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 5 2005
Added on Jan 7 2005
4 comments
184 views