title: Convert comma separated string into a HashSet
body: <p>So, how would you go about converting </p>
  
  <pre><code>String csv = "11,00,33,66,44,33,22,00,11";
  </code></pre>
  
  <p>to a hashset in the quickest-most optimized way.</p>
  
  <p>This is for a list of user-ids.</p>
  
  <h2>Update</h2>
  
  <p>I ran all the answers provided through a test program where each method was called 500,000 times for a bigger CSV string. This test was performed 5 times continously (in case program startup slowed initial method) and I got the following in milliseconds (ms):</p>
  
  <pre><code>Method One Liner-&gt;  6597
  Method Split&amp;Iterate-&gt;  6090
  Method Tokenizer-&gt;  4306
  ------------------------------------------------
  Method One Liner-&gt;  6321
  Method Split&amp;Iterate-&gt;  6012
  Method Tokenizer-&gt;  4227
  ------------------------------------------------
  Method One Liner-&gt;  6375
  Method Split&amp;Iterate-&gt;  5986
  Method Tokenizer-&gt;  4340
  ------------------------------------------------
  Method One Liner-&gt;  6283
  Method Split&amp;Iterate-&gt;  5974
  Method Tokenizer-&gt;  4302
  ------------------------------------------------
  Method One Liner-&gt;  6343
  Method Split&amp;Iterate-&gt;  5920
  Method Tokenizer-&gt;  4227
  ------------------------------------------------
  
  
  static void method0_oneLiner() {
          for (int j = 0; j &lt; TEST_TIMES; j++) {
              Set&lt;String&gt; hashSet = new HashSet&lt;String&gt;(Arrays.asList(csv
                      .split(",")));
          }
      }
  
      // ———————————————————————————————–
  
      static void method1_splitAndIterate() {
  
          for (int j = 0; j &lt; TEST_TIMES; j++) {
              String[] values = csv.split(",");
              HashSet&lt;String&gt; hSet = new HashSet&lt;String&gt;(values.length);
              for (int i = 0; i &lt; values.length; i++)
                  hSet.add(values[i]);
          }
      }
  
      static void method2_tokenizer() {
  
          for (int j = 0; j &lt; TEST_TIMES; j++) {
              HashSet&lt;String&gt; hSet = new HashSet&lt;String&gt;();
              StringTokenizer st = new StringTokenizer(csv, ",");
              while (st.hasMoreTokens())
                  hSet.add(st.nextToken());
          }
      }
  </code></pre>