title: limit of string values in a hashset while generating random values
body: <p><strong>Code :</strong></p>
  
  <pre><code>public class setExample {
  
  public static void main(String[] args) throws IOException {
  
      HashSet&lt;String&gt; hs = new HashSet&lt;String&gt;();
      HashSet&lt;String&gt; hs1 = new HashSet&lt;String&gt;();
  
      int i;
      long startTime = 0,midTime = 0;
      long endTime = 0, difference, diff;
  
  
      startTime = System.nanoTime();
  
      for(i = 0; i &lt; 10000000 ; i++)
      {
          hs.add(i+"");
      }
  
      ArrayList&lt;String&gt; arraylist = new ArrayList&lt;String&gt;(hs);
      Collections.sort(arraylist);
      endTime = System.nanoTime();
      difference = endTime - startTime;
      System.out.println("Time taken for sorted values in hashset is " +difference);
  
      midTime = System.nanoTime();
      for(i = 0; i &lt; 10000000 ; i++)
      {
          hs1.add((int)(Math.random()*100000000)+"");
      }
      ArrayList&lt;String&gt; arraylist1 = new ArrayList&lt;String&gt;(hs1);
      Collections.sort(arraylist);
      long endTime1 = System.nanoTime();
      long difference1 = endTime1 - midTime;
      System.out.println("Time taken for random values in hashset is " +difference1);
  }}
  </code></pre>
  
  <p>When running the above code I get the following output. Why is that random strings generated are having a problem ? </p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Time taken for sorted values in hashset is 14334316768
  Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
      at java.lang.Integer.toString(Integer.java:308)
      at java.lang.Integer.toString(Integer.java:118)
      at java.lang.String.valueOf(String.java:2931)
      at learn.setExample.main(setExample.java:43)
  </code></pre>