File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String.split() with null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String.split() with null values" Watch "String.split() with null values" New topic
Author

String.split() with null values

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430



The output of the above is : : : : bb

What exactly happens when the split() does a split but there is nothing in between the split as in the above example.
Is the value (in the array) classed as null or an empty string or something else?

Thanks
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
If the Strings were null then printing them out would produce 'null' for each String. Doing

gives 'true', so yes the elements of the array are indeed empty strings.

John
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I wasnt actually expecting the empty strings. I thought the contents of the array would be {bb}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String.split() with null values