Java - Write code to convert String to Int and handle null value

Requirements

Write code to convert String to Int

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(toInt(s));
    }//  w w w  .j a v  a  2 s. co  m

    public static int toInt(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        return Integer.parseInt(s);
    }
}