string parse int code example
Example 1: java string to int
int result = Integer.parseInt("500");
System.out.println(result)
Example 2: string to int java
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Copy
Example 3: parseints(str) java
int decimalExample = Integer.parseInt("20");
int signedPositiveExample = Integer.parseInt("+20");
int signedNegativeExample = Integer.parseInt("-20");
int radixExample = Integer.parseInt("20",16);
int stringExample = Integer.parseInt("geeks",29);
System.out.println(decimalExample);
System.out.println(signedPositiveExample);
System.out.println(signedNegativeExample);
System.out.println(radixExample);
System.out.println(stringExample);
Output:
20
20
-20
32
11670324
Example 4: conversion of string to integer in java
Integer.parseInt(str);
Example 5: how to convert string to int in java
There are two methods available in java to convert string to integer.
One is
Integer.parseInt() method and another one is
Integer.valueOf() method. Both these methods are static methods
of java.lang.Integer class. Both these methods throw
NumberFormatException if input string is not a valid integer.
Example 6: parseint js
parseInt(" 0xF", 16);
parseInt(" F", 16);
parseInt("17", 8);
parseInt(021, 8);
parseInt("015", 10);
parseInt(15.99, 10);
parseInt("FXX123", 16);
parseInt("1111", 2);
parseInt("15*3", 10);
parseInt("15e2", 10);
parseInt("15px", 10);
parseInt("12", 13);