[英]How to fix this error: The method toString() in the type Object is not applicable for the arguments?
I created an array of numbers.我创建了一个数字数组。 Now I want that array to be displayed in the output so I used
System.out.println
.现在我希望该数组显示在输出中,所以我使用了
System.out.println
。
But if we do that, the array won't be shown so we have to convert the array into a string just before we display it.但是如果我们这样做,数组将不会显示,因此我们必须在显示之前将数组转换为字符串。 To do that, we could use
Arrays.toString()
function.为此,我们可以使用
Arrays.toString()
函数。
It's showing the following error:它显示以下错误:
The method
toString()
in the typeObject
is not applicable for the arguments?Object
类型中的toString()
方法不适用于参数?
Below is the code I want to execute:下面是我要执行的代码:
public class Arrays {
public static void main (String[] args) {
int[] array1 = new int[] {1, 2, 3};
System.out.println((Arrays.toString(array1);
}
}
Few things:几样东西:
Arrays.toString()
accepts an array as a parameter. Arrays.toString()
接受一个数组作为参数。 Pass array1
to the methodarray1
传递给方法Arrays
is conflicting with the java.util.Arrays
class.Arrays
与java.util.Arrays
类冲突。 Either rename the class or use a direct path (demonstrated below).Try this:试试这个:
public class Arrays {
public static void main (String[] args) {
int[] array1 = new int[] {1, 2, 3};
System.out.println(java.util.Arrays.toString(array1));
}
}
[1, 2, 3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.