Here you can find the source of splitDoubles(String str, String fieldSeparator)
Parameter | Description |
---|---|
str | String of numbers to convert |
fieldSeparator | String that separates each number |
public static double[] splitDoubles(String str, String fieldSeparator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/* ww w. java 2s .com*/ * Convert a string of reals to a double array. * This will not throw any exception if the string is not well formatted. * @param str String of numbers to convert * @param fieldSeparator String that separates each number * @return an array of doubles */ public static double[] splitDoubles(String str, String fieldSeparator) { ArrayList array = new ArrayList(); // split the string into tokens StringTokenizer tokenizer = new StringTokenizer(str, fieldSeparator); while (tokenizer.hasMoreTokens()) { array.add(tokenizer.nextToken()); } // convert the tokens to double values and store them in values[] double[] values = new double[array.size()]; for (int i = 0; i < values.length; i++) { try { values[i] = Double.parseDouble((String) (array.get(i))); } catch (Exception exc) { break; } } return values; } }