+ 1
How can i print an array in java?
I tryed System.out.println(arr); but i only got some weird output. In web i found System.out.println(Array.toString(arr)); but that one doesnt work.
3 Answers
+ 5
for Arrays.toString() to work, you will need to use it from java.util. (You also forgot the s in Arrays).
You can import it like so:
import java.util.Arrays; // @top of program
System.out.println(Arrays.toString(arr));
Note* this will include the brackets [ ], you can use what the others posted if you don't want the brackets.
+ 4
If you want to print all items in that array, just do it with a for loop:
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
+ 1
Lot's of ways brother.
for(int i : array){
System.out.println(i);
}