Java Scanner Usage stringToArray(String str)

Here you can find the source of stringToArray(String str)

Description

string To Array

License

Open Source License

Declaration

public static double[] stringToArray(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Locale;
import java.util.Scanner;

public class Main {
    public static double[] stringToArray(String str) {
        Scanner scn = new Scanner(str);
        scn.useLocale(Locale.ENGLISH);
        int length = 0;
        while (scn.hasNextDouble()) {
            length++;/*ww w.  j  av  a  2s.  c  o  m*/
            scn.nextDouble();
        }
        scn.close();
        scn = new Scanner(str);
        scn.useLocale(Locale.ENGLISH);
        double[] array = new double[length];
        for (int i = 0; i < length; i++) {
            array[i] = scn.nextDouble();
        }
        return array;
    }
}

Related

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