Advertisement
mrScarlett

Tokenizer

Sep 6th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.StringTokenizer; //StringTokenizer class
  2.  
  3. class TokenTester {
  4. public static void main (String[] arguments){
  5. StringTokenizer st1, st2;
  6.  
  7. String quote1="GOOG 530.80 -9,98";
  8. st1=new StringTokenizer (quote1); ///using the 'new' operator to create new object of the StringTokenizer class
  9. System.out.println("Token 1:" +st1.nextToken());
  10. System.out.println("Token 2:" +st1.nextToken());
  11. System.out.println("Token 3:" +st1.nextToken());
  12.  
  13. String quote2="RHT@75.00@0.22";
  14. /*when you use 'new' operator a new instance of the class is
  15. * created and a method defined in the class,
  16. * called a constructor, it intialises the new object and its variables
  17. */
  18. st2 = new StringTokenizer(quote2, "@");//takes two arguements
  19. System.out.println("\nToken 1:" +st2.nextToken());
  20. System.out.println("\nToken 2:" +st2.nextToken());
  21. System.out.println("\nToken 3:" +st2.nextToken());
  22. }
  23.  
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement