473,471 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

stringTokenzier....

36 New Member
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. class Strtok {
  3.  
  4. public static void main(String [] args) {
  5.  
  6.         String Demo = "This is a string that we want to tokenize";
  7.  
  8.         StringTokenizer Tok = new StringTokenizer(Demo);
  9.         int n=0;
  10.  
  11.         while (Tok.hasMoreElements())
  12.                 System.out.println(++n +": "+Tok.nextElement());
  13.         }
can any one tell me that in S.o.println why we use double +sign wid "n" and wot the need of int n=0
May 12 '10 #1
1 1904
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. ++n
  2.  
This increments the value of n by one.

Here is your output. Where 1, 2 etc are value of n in every loop.
Expand|Select|Wrap|Line Numbers
  1. 1: This
  2. 2: is
  3. 3: a
  4. 4: string
  5. 5: that
  6. 6: we
  7. 7: want
  8. 8: to
  9. 9: tokenize
  10.  
Regards
Dheeraj Joshi
May 12 '10 #2

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.