How Do You Troubleshoot “error: no suitable method found for toString(String)”?

Problem scenario
You are trying to print out a multi-dimensional array in Java. When you try to compile your program, you get this:

error: no suitable method found for toString(String)
method Arrays.toString(long[]) is not applicable
(argument mismatch; String cannot be converted to long[])

What should you do?

You need to pass a one-dimensional array to Arrays.toString in the System.out.println statement.

Are you using Arrays.toString in a nested way?

Assuming you have a two-dimensional array called "arr2d_var1", you may have tried this:


Instead of using Arrays.toString in a nested way, make sure you have a single-dimensional array as the argument for Arrays.toString. Here is a corrected example:


Leave a comment

Your email address will not be published. Required fields are marked *