linha
is an array of String
's, and when you print an array with System.out.println(array)
, internally is called the method toString()
of the same. Only that arrays inherit this method of Object
, whose code is:
// método toString de java.lang.Object
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
That is, it returns the class name and the hashcode of the same. In the case of arrays, the documentation explains that the amount of [
represents the dimension of the array (in this case, it is one-dimensional, but if it were an array of arrays, for example, it would be [[
), and L
is the prefix that indicates that the array elements are of a class (and then comes the class name). That’s why the output starts with [Ljava.lang.String
.
That is, printing an array directly will not show the elements of it.
If you want to print the elements, you can make a loop as already suggested the another answer, or you can use Arrays.toString
:
System.out.println(Arrays.toString(linha)); // [61, 57, 18, -73, 74, -19, 15, -70, -16, -8, -80, -6, 2, -85, 8, 22, 73, -44, 34, 1]
The difference is that Arrays.toString
returns a fixed format (comma-separated elements, bounded by square brackets). For the purpose of debug may be enough, but if you want a different format, there’s no way, you need to make a loop and print in the desired format.
Another detail is that Arrays.toString
internally calls the method toString()
of each element. That is, if the elements are of a class that does not implement toString()
, the exit will be a lot of nomedaclasse@hashcode
. As in your specific case the array contains String
's, this problem does not occur.
And in the specific case of an array of String
's, you can also use String.join
(available from Java 8):
System.out.println(String.join(" | ", linha)); // 61 | 57 | 18 | -73 | 74 | -19 | 15 | -70 | -16 | -8 | -80 | -6 | 2 | -85 | 8 | 22 | 73 | -44 | 34 | 1
The join
joins all array values into a single String
, and you can choose the tab (used " | "
as an example, but it could be any other).