Parse string to Int with exception handler - Android java.lang

Android examples for java.lang:Integer

Description

Parse string to Int with exception handler

Demo Code

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;

public class Main{

    public static int toInt(String str, int defValue) {
        try {/*from  w w  w . j av a  2 s  . co m*/
            return Integer.parseInt(str);
        } catch (Exception e) {
        }
        return defValue;
    }

}

Related Tutorials