Java Scanner Usage splitToDouble(String input)

Here you can find the source of splitToDouble(String input)

Description

split To Double

License

BSD License

Declaration

public static double[] splitToDouble(String input) 

Method Source Code


//package com.java2s;
/* released under bsd licence
 * see LICENCE file or http://www.opensource.org/licenses/bsd-license.php for details
 * Institute of Applied Simulation (ZHAW)
 * Author Thomas Niederberger// w w  w.  j  a  va 2 s .c o  m
 */

import java.util.ArrayList;

import java.util.List;
import java.util.Scanner;

public class Main {
    public static double[] splitToDouble(String input) {
        Scanner s = new Scanner(input);
        s.useDelimiter("(,|;)\\s*");
        List<Double> values = new ArrayList<Double>();
        while (s.hasNext()) {
            if (s.hasNextDouble()) {
                values.add(s.nextDouble());
            } else {
                //ignore
                s.next();
            }
        }
        double[] converted = new double[values.size()];
        for (int i = 0; i < converted.length; i++) {
            converted[i] = values.get(i);
        }
        return converted;
    }
}

Related

  1. removeFirstNLines(String text, int n)
  2. removeIndexes(String xpath)
  3. removeNLinesForwardsFromStringMatch(String text, String match, int n)
  4. selectProject(List projectList)
  5. splitLines(String string)
  6. stringToArray(String str)
  7. stringToDoubleList(String s)
  8. swapElements(int length, int maxValue)
  9. termInput()