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?
Answer
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.
No comments:
Post a Comment