All I'm trying to do is print the elements in a boolean array. But instead of getting the values of the elements which are either true or false, I get a weird output like this [Z@4517d9a3. I have read about the toString but this applies to string arrays. Here is my code :
public class Class{
public static void main(String[] args) {
boolean a[] = {true, false, true, false};
boolean[] x = show(a);
System.out.println(x);
}
public static boolean[] show(boolean a[]) {
return a;
}
}
show()method does nothing.System.out.println(x);is the same asSystem.out.println(a);. 2) To print the array, you first need to turn it into a string. SeeArrays#toString(). What you're getting right now is the default implementation of thetoString()method, which includes the type of the object ([means it's an array andZindicates primitive booleans), followed by an@symbol, followed by the hash code for that particular object (4517d9a3in your case)public static String show(boolean a[]) { return Arrays.toString(a); }but callingArrays.toString()directly is more adequate IMO (and the nameshowis a bit confusing here)