Convert int to string in Java

It is generally used if we have to display number in textfield because everything is displayed as a string in form.

Source code :

public class IntToStringExample1{  
public static void main(String args[]){  
int i=200;  
String s=String.valueOf(i);  
System.out.println(i+100);//300 because + is binary plus operator  
System.out.println(s+100);//200100 because + is string concatenation operator  

Output :


Algorithm :

  1. The String.valueOf() method converts int to String.
  2. The valueOf() is the static method of String class.

Output :


Comments :