ArrayList

来源:互联网 发布:mac usb网口转换器 编辑:程序博客网 时间:2024/04/29 06:30

       目前,应用开发中经常用到ArrayList,大小是不固定的,使用方法如下:

1.创建

ArrayList<Name> nameList = new ArrayList<Name> ();//定义只能存放Name类型对象

2.加入元素

Name li =new Name();

namelist.add(li);//将li存放到集合中

3.查询大小

int  thesize= nameList.size();//查询集合大小

4.查询集合中是否存在某个特定元素

boolean isin= nameList.contains(li);//此处返回true;

5.查询集合中元素位置

int inaddress =  nameList.indexOf(li);//此处返回值为0,表示li是集合中第一个元素。

6.判断集合是否为空

boolean isempty =  nameList.isEmpty();//此处返回值为flase

7.删除集合中元素

 nameList.remove(li);//删除集合中元素li

0 0
原创粉丝点击