Java学习-ArrayList

ArrayList

数组结构实现,查找块,增删慢
JDK1.2版本,运行效率快,线程不安全

使用方法

/*
Arraylist使用
存储结构:数组结构,查找块增删慢
 */
public class Demo02 {
    public static void main(String[] args) {
        //创建集合
        ArrayList arrayList=new ArrayList();
        Student s1=new Student("张三",15);
        Student s2=new Student("李斯",16);
        Student s3=new Student("王五",18);
        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);
        System.out.println(arrayList.toString());
        //删除
        arrayList.remove(new Student("张三",15));
        System.out.println(arrayList.toString());
        //遍历
        Iterator it=arrayList.iterator();
        while (it.hasNext()){
            Student s=(Student)it.next();
            System.out.println(s.toString());
        }
        ListIterator lit=arrayList.listIterator();
        while (lit.hasPrevious()){
            Student s=(Student)lit.previous();
            System.out.println(s.toString());
        }
        //判断
        System.out.println(arrayList.contains(new Student("李斯",16)));
        //查找
        System.out.println(arrayList.indexOf(s2));
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值