I have several arrays in a class
I want to implement toString() to print all values.
How to do this?
public String var1[];
public int var2[];
public String var3[][];
public int var4[];
public int var5[][];
public String toString() {
for(String s : var1) {
System.out.println(s.toString());
}
return null;
}
That prints all var1[] content but how to print all?? Do I have to put a loop for every one of them?
You can use the Arrays.toString()
static helper method as follows:
String lines[] = getInputArray();
System.out.println(java.util.Arrays.toString(lines));
I think what you are looking for is Arrays.deepToString()
Refer to this link for more details. It takes an array and calls toString()
on every element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With