typecasting string to int in java code example
Example 1: string to int java
int result = Integer.parseInt(number);
Example 2: string to int java
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Copy
Example 3: convert a string to int in java
String myString = "1234";
int foo = Integer.parseInt(myString);
Example 4: converter string para int java
package br.com.dicasdejava.fundamentos;
public class ConverterStringParaInt {
public static void main(String[] args) {
String numero = "25";
int numeroConvertido = Integer.parseInt(numero);
int numeroVezes2 = numeroConvertido * 2;
System.out.println("Resultado: " + numeroVezes2);
}
}
Example 5: parse string to int java
String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);
Example 6: java string to integer
String example = "1";
int converted = Integer.parseInt(example);