Java动态数组Arraylist存放自定义数据类型
class Point
{
int x;
int y;
public Point(int x,int y)
{
this.x=x;
this.y=y;
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Point> myPoint=new ArrayList<Point>();
Point temp=new Point(5,10);
myPoint.add(temp);
**Point p = (Point)myPoint.get(0);**
System.out.println("x的值为:"+p.x);
System.out.println("y的值为:"+p.y);
}
}
ArrayList可以存放任何对象的引用;其是有序的可重复的;取出时是Object对象,需要强制转化