4 Replies Latest reply: Oct 3, 2012 3:09 PM by 939520 RSS

    StringTokenizer not working as I was expecting

    965953
      Hi all, I have a question related to StringTokenizer class. It is not giving me the results I was expecting. May be my understanding is wrong.

      This is my code:
      String string = null;
      String delimiter = null;
      StringTokenizer tokenizer = null;
      
                
      string = "Normal";
      delimiter = "_crMULT_";
                
      System.out.println("string=" + string);
      System.out.println("delimiter=" + delimiter);
                
      tokenizer = new StringTokenizer(string, delimiter);
      while (tokenizer.hasMoreTokens()) {
           System.out.println("tokenizer.nextToken()=" + tokenizer.nextToken());
      }
      This is the result I am getting:
      string=Normal
      delimiter=_crMULT_
      tokenizer.nextToken()=No
      tokenizer.nextToken()=mal

      I thought this is the result I will get:
      string=Normal
      delimiter=_crMULT_
      tokenizer.nextToken()=Normal


      What I am doing wrong here?

      Edited by: 962950 on Oct 3, 2012 10:12 AM