I am currently working with arrays, and everytime I need to print one I do a for loop.
System.out.print("[");
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + ", ");
}
System.out.println("]");
This seems like a feature that would be built into java (I am using java). Is there a built in way to print arrays?
You could use:
Arrays.toString(arr)
for normal arrays and/or
Arrays.deepToString(arr)
for arrays within arrays.
Both these methods return the string representation of the array.
See the Arrays docs for more.
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