Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 3 January 2017

Write a Java Program to Convert Numeric String into Int ?

Their are some ways to convert String into int in Java:

1 ) Integer.parseInt(String s);
This method throws NumberFormatException if given String is not in number format.This method returns primitive int type.

2 ) Integer.valueOf(String s);
This method throws NumberFormatException if given String is not in number format.This method return Integer, which is object representation of Integer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
public class ConvertNumericStringToInt {
 
 public static void main(String[] args) {
  
  //First Way : by using Integer.parseInt()
  int a = Integer.parseInt("1234");
  System.out.println("NUM 1 : "+a);
  
  //Second Way : by using Integer.valueOf()
  Integer b = Integer.valueOf("5689");
  System.out.println("NUM 2 : "+b);
  
 }
}
Output :

NUM 1 : 1234
NUM 2 : 5689


      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment