How to convert String to int and int to String in Java
1. String to int
try{
String str="123";
int k = Integer.parseInt(str);
}catch(NumberFormatException nfe){
System.out.println("String can't be converted into int as it is not in correct format");
}
2. int to String
int k=123;
String str= k+"";
or
String str2= k.toString();
1. String to int
try{
String str="123";
int k = Integer.parseInt(str);
}catch(NumberFormatException nfe){
System.out.println("String can't be converted into int as it is not in correct format");
}
2. int to String
int k=123;
String str= k+"";
or
String str2= k.toString();