Java 高阶-类

ArrayList:
创建:
ArrayList list = new ArrayList(); 判空:list.isEmpty();
添加:
list.add(Object object);
list.addAll(Collection col);【添加一个集合对象】 长度:list.size();
插入:
list.add(index x,Object object);
list.addAll(index,Collection col); 判存:list.contains(元素值,如"makle");
取值:
list.get(index x);
移除:
list.remove(index x); list.remove(list中的元素);
遍历:
1、for循环 ; 2、Iterator(遍历器)【Iterator iterator = list.iterator();
while(iterator.hasNext())
iterator.next();
】 ; 3、增强版的for循环 :for(Object o: list):{}
4、转换为数组:Object[] o = list.toArray(); 再遍历

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章