Java Programming Examples Tutorial Index

Java String Programs

This Java program converts String to Integer.



Usually String to int conversion is required when we need to do some mathematical operations in the string variable that contains numbers. This situation normally arises whenever we receive data from user input via textfield or textarea, data is obtained as string and we required to convert string to int.

Java Integer class has parseInt() static method, which is used convert string to int.

Syntax:

public static int parseInt(String s)

Example:

public class StrToInt {
        
 public static void main(String args[]) {
  String str = "123";
  int i = Integer.parseInt(str);
  System.out.println(str + 50); //12350 because its concatenate to value.
  System.out.println(i + 50); //173 because +(plus) is binary plus operator. 
 }
        
}

Program Output:

12350
173


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram