get Int List Form String - Android java.lang

Android examples for java.lang:Integer

Description

get Int List Form 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 ArrayList<Integer> getIntFormStr(String str) {
        Pattern p = Pattern.compile("[^0-9]");
        Matcher m = p.matcher(str);
        String result = m.replaceAll("");
        ArrayList<Integer> digitList = new ArrayList<Integer>();
        for (int i = 0; i < result.length(); i++) {
            digitList.add(Integer.parseInt(result.substring(i, i + 1)));

        }//from   w  w  w. j  ava 2 s .c om
        return digitList;
    }

}

Related Tutorials