Search This Blog

Friday, 12 December 2014

String to Integer conversation and Integer to String conversation

Conversation from String to integer and integer to String is so easy. Java provide for below method to conversation.






 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public class Main {
 public static void main(String args[]) {  
  /**
   * String to integer conversation
   */
  String strVar="123";
  int intVar=Integer.parseInt(strVar);
  System.out.println("Integer variable="+intVar);

  /**
   * Integer to String conversation
   */
  int var1=123;
  String var2=null;
  var2=String.valueOf(var1);
  System.out.println("String variable="+var2);
 }
}
Output
Integer variable=123
String variable=123

No comments:

Post a Comment