Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert int to string java program


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.

Example:

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

Output:

String is: 123

Download this example.

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.

Example:

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

Output:

String is: 123

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status