• Post Reply Bookmark Topic Watch Topic
  • New Topic

split method in Java  RSS feed

 
Ruchi Saini
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
547
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ruchi Saini
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for replying...so it will not matter what is the value of that -ve number
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you looked at the documentation for String#split(String, int)?
 
Ruchi Saini
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!