为什么我得到Java的垃圾值时,打印数组? [英] Why do I get garbage values when print arrays in Java?

查看:133
本文介绍了为什么我得到Java的垃圾值时,打印数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  打印在Java中阵列最简单的方法


我怎么连打印数组?我想尝试一些方法和所有我不断获取都是垃圾值。我试图导入阵列库 - 仍然没有工作。

  INT [] X = {1,2,3,4,5};
    INT []ÿ;
    Y = x.clone();
    的System.out.println(X);
    的System.out.println(Y);


解决方案

这不是垃圾值;它是的toString()实施 INT []

如果您想打印数组的内容

 公共无效printArray(INT [] arrray){
 对于(INT编号:数组){
   的System.out.println(数);
 }
}


另请参见

Possible Duplicate:
Simplest way to print an array in Java

How do I even print arrays? I'm trying to experiment on some methods and all I keep on getting are garbage values. I tried to import the Arrays library - still didn't work.

    int []x = {1, 2, 3, 4, 5};
    int []y;
    y = x.clone();
    System.out.println(x);
    System.out.println(y);

解决方案

It is not a garbage value; it is the toString() implementation of int[],

If you want to print the contents of array

public void printArray(int[] arrray){
 for(int number: array){
   System.out.println(number);
 }
}


See Also

这篇关于为什么我得到Java的垃圾值时,打印数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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