title: Thread Safe String Split
body: <p>I have ran a split test with StringTokenizer and String's method indexOf() followed by substring(). After result I have to knew, the second one is faster than StringTokenizer. But my question is which is best for Thread safety?</p>
  
  <p>String split using StringTokenizer:</p>
  
  <pre><code>String sample=null;
  StringTokenizer tokens = new StringTokenizer("FF#Mukil","#");
  
  if(tokens.hasMoreTokens())
  {
      sample= tokens.nextToken();
      System.out.println(sample);
  }
  </code></pre>
  
  <p>String split using String's method:</p>
  
  <pre><code>String sample= "FF#Mukil";
  int pos=sample.indexOf('#');
  System.out.println(sample.substring(0,pos));
  </code></pre>
  
  <p>In these examples, sample is global variable
  Thanks in advance</p>
  
  <p>Edited:
  In Previous first example is like below</p>
  
  <pre><code>StringTokenizer tokens = new StringTokenizer("FF#Mukil","#");
  
      if(tokens.hasMoreTokens())
      {
          String sample= tokens.nextToken();
          System.out.println(sample);
      }
  </code></pre>
  
  <p>I have changed it like below</p>
  
  <pre><code>String sample=null;
  StringTokenizer tokens = new StringTokenizer("FF#Mukil","#");
  
      if(tokens.hasMoreTokens())
      {
          sample= tokens.nextToken();
          System.out.println(sample);
      }
  </code></pre>
  
  <p>Edited: Added java file source.</p>
  
  <pre><code>//FileName=MySplitUtil.java
  import javax.servlet.http.HttpServletRequest;
  import java.util.StringTokenizer;
  public class MySplitUtil
  {
      public static void setUsername_locale(HttpServletRequest request)
      {
          String value = (String) request.getAttribute("userLocale"); // userLocale's sample value looks like ffmukil$en_US
          splite1(value,request);
          splite2(value,request);
      }
      private static void splite1(String value,HttpServletRequest request)
      {
          StringTokenizer tokens = new StringTokenizer(value,"$");
          String username=null;
          String locale=null;
          if(tokens.hasMoreTokens())
          {
              username = tokens.nextToken();
              locale = tokens.nextToken();
          }
          request.setAttribute("usrName",username);
          request.setAttribute("usr_Locale",locale);
      }
      private static  void splite2(String value,HttpServletRequest request)
      {
          int pos = value.indexOf('$');
          String username = value.substring(0,pos);
          String locale = value.substring(pos+1,value.length());
          request.setAttribute("usrName",username);
          request.setAttribute("usr_Locale",locale);
      }
  }
  </code></pre>