Java Int to string

Java int to string example using Integer.toString()

The Integer.toString() method is used to convert int to string in Java. It takes an integer value as an argument and returns a string representing of it.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.w3schools;
public class IntToString {
public static void main(String args[]){
int num = 123;
String str = Integer.toString(num);
System.out.println("String is: "+str);
}
}
package com.w3schools; public class IntToString { public static void main(String args[]){ int num = 123; String str = Integer.toString(num); System.out.println("String is: "+str); } }
package com.w3schools;

public class IntToString {
  public static void main(String args[]){
	  int num = 123;
	  String str = Integer.toString(num);
	  System.out.println("String is: "+str);
  }
}

Output

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
String is: 123
String is: 123
String is: 123

 

Java int to string example using String.valueOf()

The String.valueOf() method is used to convert int to string in Java. It takes an integer value as an argument and returns a string representing of it.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.w3schools;
public class IntToString {
public static void main(String args[]){
int num = 123;
String str = String.valueOf(num);
System.out.println("String is: "+str);
}
}
package com.w3schools; public class IntToString { public static void main(String args[]){ int num = 123; String str = String.valueOf(num); System.out.println("String is: "+str); } }
package com.w3schools;

public class IntToString {
  public static void main(String args[]){
	  int num = 123;
	  String str = String.valueOf(num);
	  System.out.println("String is: "+str);
  }
}

Output

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
String is: 123
String is: 123
String is: 123