Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Certification
»
Programmer Certification (OCPJP)
String.split() with null values
O. Ziggy
,
Ranch Hand
Jan 01, 2012 06:56:19
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
class ZiggyTest{ public static void main(String[] args) { String str = "aaaaaaaaabb"; String [] s = str.split("a{3}"); for(String x : s){ System.out.print(" : " + x); } } }
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
Jan 01, 2012 12:25:57
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
If the Strings were null then printing them out would produce 'null' for each String. Doing
s[0].isEmpty()
gives 'true', so yes the elements of the array are indeed empty strings.
John
O. Ziggy
,
Ranch Hand
Jan 01, 2012 14:32:57
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
I wasnt actually expecting the empty strings. I thought the contents of the array would be {bb}
Post by:
autobot
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 1359 times.
Similar Threads
splitting string into 2 variable
difference between null string and ""
String Tokenizing doubt
Garbage Collection
Why it want super class constructor
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:42:25
.