jQuery in Action, 3rd edition
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String.split() with null values" Watch "String.split() with null values" New topic

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?

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.

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
It's not a secret anymore!