Parse string To Int - Android java.lang

Android examples for java.lang:Integer

Description

Parse string To Int

Demo Code

import android.text.Html;
import android.text.TextUtils;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main{

    public static int stringToInt(String s) {
        return stringToInt(s, 0);
    }/*from  ww w  .ja  v  a 2 s.  co m*/
    public static int stringToInt(String s, int defaultValue) {
        if (s == null)
            return defaultValue;
        try {
            return Integer.valueOf(s);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }

}

Related Tutorials