This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in split(). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in split()." Watch "Doubt in split()." New topic
Author

Doubt in split().

Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361


The above is a question from whizlab simulator. Can anyone please tell me how the output is coming to be 4?
I thought the split method is supposed to split a string around matches of a regex. here regex is a{3} so doesnt that leave bb to be the two tokens.??
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The tokens are "", "", "", "bb" as shown below:

[ August 13, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
BUt how can a string of zero length be considered a token when I havent used any kind of greedy quantifier? And going by the explanation. there is a token on the left of the first ""aaa. Then why isnt there also a token just before the BB. like aaa""bb".?
I hate regexing
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The "bb" is the token. Just before this token there is the separator "aaa".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in split().