0
Print out an array
How can i print out the whole array? if i do int [] arr = {2, 3, 4}; System.out.println(arr); it outputs strange characters. i suppose i can do it with for loop, but than i get the numbers one by one, not the whole array.
4 Answers
+ 6
https://code.sololearn.com/cFZw4c01m60d/?ref=app
Arrays.toString(arr) for one-dimensional array and Arrays.deepToString(arr) for multi-dimensional.
+ 2
Your are right about the loop. In Java, arrays have a length property which you can use in a for loop to walk trough the array, one by one.
If you don't care about the (loss of) the data type and just want the array at a whole printed to the screen, you can import Arrays (import java.util.Arrays) and use the toString method, see https://code.sololearn.com/c3yWe9DKbJr1
(I haven't set the code example to "Public" and I'm not certain whether it can be linked anyway. If this doesn't work, please just drop me a line.)
+ 2
for(int a=0;a<arr.length;a++){
System.out.println(arr[a]);
}
this is it.
+ 1
thanks for help to everybody, i got it, links worked fine!