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对象,需要强制转化
博客介绍了ArrayList的特性,它可存放任何对象的引用,是有序且可重复的。同时指出从ArrayList中取出对象时,得到的是Object对象,需要进行强制转化。

被折叠的 条评论
为什么被折叠?



