English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java program converts String to integer

In Java, use the Integer.parseInt() method to convert a String to an integer.

Let's take a string first.

String \tstr \t= \t"200\";

Now let's convert it to an integer.

int \tval \t= \tInteger.parseInt(str);

Now let's see the complete example.

Example

public \tclass \tDemo \t{
   public \tstatic \tvoid \tmain( \tString \targs\[\t) \t{
      String \tstr \t= \t"200\";
      int \tval \t= \tInteger.parseInt(str);
      System.out.println("Integer: \t"+val);
   }
}

Output Result

Integer: 200