java的打印与Arrays.toString阵列()错误 [英] java printing an array with Arrays.toString() error

查看:287
本文介绍了java的打印与Arrays.toString阵列()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我尝试打印的int数组在我的计划,并按照这些指令的最简单的方法打印在Java中数组

写了下面的code:

  INT []总访问量= //方法返回int数组
    的System.out.println(Arrays.toString(总计));

但它不会编译说


  

类对象toString方法不能被应用到给定的类型。
  要求:无参数
  发现:INT []
  原因:实际的和正式的参数列表的长度不同


为什么会这样?难道我没有通过我的数组作为参数传递给的toString?如果没有,我怎么使用的toString?

感谢您!


解决方案

  

类Object toString方法不能被应用到给定的类型。要求:未发现参数:INT []的原因:实际的和正式的参数列表的长度不同


可能是你有一个名为变量阵列,这就是为什么编译器抱怨你试图调用思维 Object.toString() ,它不带任何参数。

尝试

 的System.out.println(java.util.Arrays.toString(总计));

So I was trying to print an array of ints in my program, and following these instructions Simplest way to print an array in Java

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

这篇关于java的打印与Arrays.toString阵列()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆