wood burning stoves 2.0*
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}
 
Consider Paul's rocket mass heater.
 
subject: String.split() with null values
 
Similar Threads
Why it want super class constructor
difference between null string and ""
Garbage Collection
splitting string into 2 variable
String Tokenizing doubt