Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java printing an array with Arrays.toString() error

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!

like image 755
Levon Tamrazov Avatar asked Jan 23 '26 09:01

Levon Tamrazov


1 Answers

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)); 
like image 125
Bhesh Gurung Avatar answered Jan 25 '26 21:01

Bhesh Gurung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!