Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to split each String in list1 on "," and attempt to parse each String that gets split out:</p> <pre><code> ArrayList&lt;Double[]&gt; results = Lists.newArrayList(); for( String s : list1 ) { String[] splitStrings = s.split(","); Double[] doublesForCurrentString = new Double[splitStrings.length]; for(int i=0; i&lt;splitStrings.length; i++){ try { doublesForCurrentString[i] = Double.valueOf(splitStrings[i]); } catch( NumberFormatException ex ) { // No action. } } results.add(doublesForCurrentString); } Double[][] doubleArray = (Double[][])results.toArray(); </code></pre> <p>Crucial points:</p> <ul> <li><strong>EDIT</strong>: As @Tim Herold points out, you're probably better of performance-wise avoiding attempting to parse content you know to be non-numeric. In this case, I'd still split first and then just put in code that prevents you from attempting to parseDouble() on the first split String in each line, rather than trying to do String replacement before the split; that will be faster (and if we're not concerned about performance, then try/catch is perfectly fine and more readable). <strong>ORIGINAL</strong>: You need a try/catch when you try to parse the doubles, in case there's any invalid input. Bonus: you don't need to remove the non-numeric text now, you can just let this try/catch handle it.</li> <li>Your strings have <strong>two</strong> doubles in each of them. You're not going to be able to just strip the text at the beginning and then parse the rest, because it's not going to be a valid double.</li> <li>ArrayLists are generally easier to use; I'd opt for returning <code>ArrayList&lt;Double&gt;</code> (or <code>ArrayList&lt;ArrayList&lt;Double&gt;&gt;</code>) over <code>Double[]</code> or <code>Double[][]</code> any day of the week. There are certainly situations where I'd do differently, but yours doesn't sound like one of them to me.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload