get Int Array from String - Android java.lang

Android examples for java.lang:Integer

Description

get Int Array from String

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static Integer[] getIntArray4String(String str) {
        ArrayList<Integer> intlist = new ArrayList<Integer>();

        String s = "\\d+.\\d+";
        Pattern pattern = Pattern.compile(s);
        Matcher ma = pattern.matcher(str);

        while (ma.find()) {
            System.out.println(ma.group());

        }/*from w w w  .  j ava  2 s .com*/

        Integer[] intArray = (Integer[]) intlist.toArray();
        return intArray;

    }

}

Related Tutorials