So I was trying to print an array of ints in my program, and following these instructions What's the simplest way to print a Java array?
wrote the following code:
int[] totals = //method that returns int array
System.out.println(Arrays.toString(totals));
But it wont compile saying that
"method toString in class Object cannot be applied to given types. required: no arguments found: int[] reason: actual and formal argument list differ in length"
Why does it do that? Do I not pass my array as an argument to toString? If not, how do I use toString?
Thank you!
method toString in class Object cannot be applied to given types. required: no arguments found: int[] reason: actual and formal argument list differ in length
May be you have a variable named Arrays, that's why the compiler is complaining thinking that you are trying to invoke the Object.toString(), which doesn't take any argument.
Try
System.out.println(java.util.Arrays.toString(totals));
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