本文介绍了为什么我得到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的垃圾值时,打印数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:48