Java Regex Double Validate parseDoubleList(String list)

Here you can find the source of parseDoubleList(String list)

Description

Scans an input string for double values.

License

Open Source License

Declaration

public synchronized static double[] parseDoubleList(String list) 

Method Source Code

//package com.java2s;

import java.util.*;
import java.util.regex.*;

public class Main {
    static final Matcher fpMatch = Pattern
            .compile("([-+]?((\\d*\\.\\d+)|(\\d+))([eE][+-]?\\d+)?)(\\%|in|cm|mm|pt|pc|px|em|ex)?").matcher("");

    /**/*from   ww w.  j  ava 2s .c o m*/
     * Scans an input string for double values.  For each value found, places
     * in a list.  This method regards any characters not part of a floating
     * point value to be seperators.  Thus this will parse whitespace seperated,
     * comma seperated, and many other separation schemes correctly.
     */
    public synchronized static double[] parseDoubleList(String list) {
        if (list == null)
            return null;

        fpMatch.reset(list);

        LinkedList doubList = new LinkedList();
        while (fpMatch.find()) {
            String val = fpMatch.group(1);
            doubList.add(Double.valueOf(val));
        }

        double[] retArr = new double[doubList.size()];
        Iterator it = doubList.iterator();
        int idx = 0;
        while (it.hasNext()) {
            retArr[idx++] = ((Double) it.next()).doubleValue();
        }

        return retArr;
    }
}

Related

  1. parseDouble(Object object)
  2. parseDouble(Object value, Double replace)
  3. parseDouble(String myString)
  4. parseDouble(String s)
  5. parseDouble(String str)