How to convert Array content to a String in Java

  • A+
Category:Languages

How can the Array content be converted a String in Java?

Example:

int[] myArray = {1,2,3}; 

The output has to be:

"123" 

Arrays.toString(myArray) is returning:

"[1, 2, 3]" 

and myArray.toString(), returns:

[I@12a3a380 

So none of them works. Is there a function for this?

This question might look similar to (this), but is actually different. I am really asking for a String made of all the array entries.

 


String joined = Arrays.stream(myArray)             .mapToObj(String::valueOf)             .collect(Collectors.joining(""));  System.out.println(joined);    

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: