title: From arrayList to long[]
body: <p>I am doing a method that needs to return a long[]. It looks like this:</p>
  
  <pre><code>public long[] parseString(String input)
  </code></pre>
  
  <p>input are strings like:</p>
  
  <ul>
  <li>1, 3, 4</li>
  <li>10, 30, 40, 50</li>
  </ul>
  
  <p>Inside parseString I use a regex to get all numbers and add them to an ArrayList as I can't know how many oconcurrences it will find.</p>
  
  <p>At the end I create a long[] with the size of the arrayList and do a for each to add it to the long[] var.</p>
  
  <p>Another way would be:
  First count every occurrence with a</p>
  
  <pre><code>while ( matcher.find() ) size++;
  </code></pre>
  
  <p>and then with size create a long[] of size size and do a:
  matcher.reset() and now save the long values in the long[] variable.</p>
  
  <p>Which do you think it's the best?</p>
  
  <p>Is there a better way to do this?</p>
  
  <p>Remember I can't change the method signature :(</p>