string To Int - Java java.lang

Java examples for java.lang:String Parse

Description

string To Int

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String s = "java2s.com";
        System.out.println(strToInt(s));
    }//from   w  w w . jav a 2 s .com

    public static int strToInt(String s) {
        int val = 0;
        try {
            val = Integer.parseInt(s);
        } catch (Exception ex) {
            val = 0;
        }
        return val;
    }
}

Related Tutorials