Int a[] = {1,2};
String s = a.toString(); //what's going on here.
My output is
I@something for integer array. C@something for char array.
How to I correctly convert any array into string.
Int a[] = {1,2};
String s = a.toString(); //what's going on here.
My output is
I@something for integer array. C@something for char array.
How to I correctly convert any array into string.
You can use Arrays.toString(array)
Like for example :
Int a[] = {1,2};
System.out.println("Array as String:"+Arrays.toString(array))
It will output:
Array as String:[1,2]
Have you tried using char[]
array? If it suits your need this would help you:
char[] chars = {'1', 'a'};
String string = new String(chars);
System.out.println(string);
Output: 1a
You can create your own implementation for learning what is going on background.
int a[] = {1,2};
printArray(a);
public void printArray(int[] a) {
System.out.print("Array={");
for(int singleElement : a) {
print(singleElement);
}
System.out.println("}");
}