试图打印出ArrayList的内容 [英] Trying to print out the contents of an ArrayList
本文介绍了试图打印出ArrayList的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打印出ArrayListlist的内容,但我不断得到我认为的元素位置而不是内容。
I'm trying to print out the contents of the ArrayList "list", but I keep getting what I think is the locations of the elements and not the contents.
import java.util.*;
public class Assignment23 {
public static void main (String[] args){
ArrayList<Point> list = new ArrayList<Point>();
for(int i = 0; i < 99; i++){
list.add(new Point());
}
Collections.sort(list);
System.out.println(""+list);
}
}
class Point implements Comparable<Point>{
int x = (int)(Math.random()*-10);
int y = (int)(Math.random()*-10);
推荐答案
打印出<$ c $的内容c> ArrayList ,使用 for循环
:
for (Point p : list)
System.out.println("point x: " + p.x ", point y: " + p.y);
这篇关于试图打印出ArrayList的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文