How can the Array
content be converted to 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 literally 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With