Results 1 to 4 of 4
Thread: Trim for null string
- 02-08-2011, 06:39 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Trim for null string
Hi,
Please help.
Why we will getting NullPointerException when we trying to trim a NULL string,
but won't be getting error if we trim a string with "".
Example: string a= null; System.out.println(a.trim()); -> NullPointerException
string b= ""; System.out.println(b.trim()); -> No error
Thanks..
-
There's no such thing as a null string. There is only null, a variable that refers to no object, nothing. So what happens here is the same thing that happens when you try to call any method of a null. This shouldn't come as a surprise.
- 02-08-2011, 06:53 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Got it, thanks for your reply.
If i have a string variable that get the NULL value from database, what is the best way to check before to trim it?
-
Similar Threads
-
String passed as argument to a constructor returns null value
By eLancaster in forum New To JavaReplies: 1Last Post: 02-07-2011, 10:44 AM -
String.trim() method help.....
By arson09 in forum New To JavaReplies: 6Last Post: 04-23-2010, 01:19 AM -
How to trim text in viewer
By diva_garg in forum SWT / JFaceReplies: 4Last Post: 08-26-2008, 02:03 PM -
String returning null value
By impact in forum New To JavaReplies: 7Last Post: 08-03-2008, 07:49 AM -
String trim
By Java Tip in forum Java TipReplies: 0Last Post: 01-21-2008, 04:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks