简体   繁体   English

如何修复此错误:对象类型中的 toString() 方法不适用于参数?

[英]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 type Object 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传递给方法
  • Your class name Arrays is conflicting with the java.util.Arrays class.您的类名Arraysjava.util.Arrays类冲突。 Either rename the class or use a direct path (demonstrated below).重命名类或使用直接路径(如下所示)。
  • You are missing some ending brackets你缺少一些结束括号

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));
  }
}

Which prints :哪个打印

[1, 2, 3]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解析类型为Object的方法toString()不适用于参数(InputStream) - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) 为什么 Character.toString 不给出错误 Object 类型中的方法 toString() 不适用于参数 (int) - Why doesn't Character.toString give the error The method toString() in the type Object is not applicable for the arguments (int) Object 类型中的 toString() 方法不适用于参数 (Collection<Describe> ) - The method toString() in the type Object is not applicable for the arguments (Collection<Describe>) 如何修复 Main 类型中的方法不适用于参数 () - How to fix the method in the type Main is not applicable for the arguments () 如何修复错误:Map 类型中的 put(Integer, Integer) 方法<integer,integer>不适用于 arguments (int, String)</integer,integer> - How to fix error: The method put(Integer, Integer) in the type Map<Integer,Integer> is not applicable for the arguments (int, String) 类型object中的equals(object)方法不适用于参数 - the method equals(object) in the type object is not applicable to the arguments 如何调试“类型X中的方法或匹配器不适用于自变量”的错误? - How to debug an error of “The method or Matcher in the type X is not applicable for the arguments”? ExecutorService类型中的方法invokeAll不适用于参数错误 - Method invokeAll in the type ExecutorService is not applicable for the arguments error 为什么 addNode() 方法返回编译错误“该方法...类型...不适用于参数...”,我该如何解决? - Why are the addNode() methods returning the compile error "The method...in type...is not applicable for the arguments...", and how do I fix it? 类型中的方法不适用于参数 - Method in the type is not applicable to the arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM