aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in split(). Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Doubt in split().
 
Similar Threads
split()...
parsing a string an basis of a delimetre
How we can Count the no.of words in a given String
Split a string
String.split question