safe Parse Int - Java java.lang

Java examples for java.lang:String Parse

Description

safe Parse Int

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String toParse = "java2s.com";
        System.out.println(safeParseInt(toParse));
    }//from w  ww. j  ava2  s  .c o  m

    public static Integer safeParseInt(String toParse) {
        try {
            return Integer.valueOf(toParse);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}

Related Tutorials