给出垃圾值

时间:2013-11-22 20:50:03

标签: java arrays

请参阅此程序代码:

public class RemoveTest {

public static void main(String[] args) {
    // TODO Auto-generated method stub


System.out.print(remove(new int[] {1, 2, 3, 4}));


}

static int [] remove(int[] a){
    int[] b = new int[a.length - 1];
    System.arraycopy(a, 1, b, 0, a.length - 1);
    return b;

}

}

但是给出了垃圾输出。我在Eclipse IDE上尝试它

1 个答案:

答案 0 :(得分:2)

您已经看到了Object's toString() method的结果;数组也是对象。

使用Arrays.toString()

System.out.print(Arrays.toString(remove(new int[] {1, 2, 3, 4})));