/** * @author lautturi.com * Java example: check if able to parse string to int */ import java.util.*; public class Lautturi { public static boolean isParseAble2Int(String input) { try { Integer.parseInt(input); return true; } catch (final NumberFormatException e) { return false; } } public static void main(String[] args) { String str ="1234"; if(isParseAble2Int(str)) { System.out.println("the string can be parsed into int"); } } }
output:
the string can be parsed into int