jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Token Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Token Question" Watch "Token Question" New topic
Author

Token Question

Alan Hermin
Ranch Hand

Joined: Feb 16, 2006
Posts: 290
Hi Ranchers.......
i will take a test at these days...
i have a question about Tokens: I Think if i use the token using <String.split> method , THEN use the same source and regex at the Scanner class, THE OUTPUT MUST SAME,,Take The code:


code:
--------------------------------------------------------------------------------

String input="10 Apples 20 Oranges 33 Pears"; Scanner sc=new Scanner(input).useDelimiter("\\d*"); while(sc.hasNext()) System.out.println(">"+sc.next()+"<");

--------------------------------------------------------------------------------


--------------------------------------------------------------------
And the code:

code:
--------------------------------------------------------------------------------

String input="10 Apples 20 Oranges 33 Pears"; String[]arr=input.split("\\d*"); for(String xx:arr){ System.out.println(">"+xx+"<"); }

--------------------------------------------------------------------------------




THE OUTPUT in the String.split version return more data than the first one.
PLEASE HELP..
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Token Question
 
Similar Threads
Tokens
What is wrong with this code?
scanner regex question
Help in Regex
Searching using Scanner class exp. in K&B SCJP6