how to turn an integer into a string code example

Example 1: int to string java

int x = 3;

Integer.toString(int)

Example 2: turn number into array javascript

const myNumber = 1245;
function numberToArray(number) {
  	let array = number.toString().split("");//stringify the number, then make each digit an item in an array
  	return array.map(x => parseInt(x));//convert all the items back into numbers
}
//use the function
var myArray = numberToArray(myNumber);

Example 3: java int to string

String s = String.ValueOf(x); //converts a int x to a String s

Example 4: how to make an int into a string java

int i=10;  
String s=String.valueOf(i);

Example 5: turn array into string

const elements = ['Fire', 'Air', 'Water'];

console.log(elements.join());
// expected output: "Fire,Air,Water"

console.log(elements.join(''));
// expected output: "FireAirWater"

console.log(elements.join('-'));
// expected output: "Fire-Air-Water"

Tags: