Forums Register Login

split method in Java

+Pie Number of slices to send: Send
Hi,

I am not able to understand how split method in java works

If I have

value.toString().split(";", -6);

or


value.toString().split(";", -2);

what will be the difference...basically , i want to know how does negative limit in a split works

Thanks
+Pie Number of slices to send: Send
According to the JavaDoc, all negative numbers behave the same as a limit:

If n is non-positive then the pattern will be applied as many times as possible and the array can have any length

 
+Pie Number of slices to send: Send
thanks for replying...so it will not matter what is the value of that -ve number
+Pie Number of slices to send: Send
Welcome to the Ranch

Have you looked at the documentation for String#split(String, int)?
+Pie Number of slices to send: Send
yes, it says If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. so it seems to me that there is no difference where value is -2 or -3 or -4...for all -ve values, output is same
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 469 times.
Similar Threads
A Practise application - some advice
Basic Questions on EJB3
Cross-Application, Possibly Cross-Language
How can you use a loop to track the number of times an option has been chosen?
A rather long post of me talking gibberish and asking lots of questions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:46:06.