get Int from String - Java java.lang

Java examples for java.lang:int Parse

Description

get Int from String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String content = "java2s.com";
        System.out.println(getInt(content));
    }//  ww w  .j  av  a  2s.c o  m

    public static int getInt(String content) {
        int intContent;
        try {
            intContent = Integer.parseInt(content);
        } catch (Exception e) {
            intContent = 0;
        }
        return intContent;
    }
}

Related Tutorials