aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String.split() method and Regex question  from Whizlabs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String.split() method and Regex question  from Whizlabs" Watch "String.split() method and Regex question  from Whizlabs" New topic
Author

String.split() method and Regex question from Whizlabs

Ida Achi
Greenhorn

Joined: Oct 02, 2009
Posts: 25

Please assist me understand why the following code prints 4 and not 3? Thanks



Anshul Agrawal
Greenhorn

Joined: Jul 15, 2008
Posts: 19
The String.split() method splits a string around matches of the given regular expression. The return value is a String array containing the tokens.

In this case we split on the expression "a{3}" and the tokens are stored in the array s. Here, the regular expression a{3} is searching for three occurrences of the letter "a" in a row. ...

To match a pattern exactly n number of times, we specify the number inside a set of braces.
it will have 3 blank strings and one "bb"



Regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String.split() method and Regex question from Whizlabs