Java集合框架学习笔记(一)LIST

/*Collection
    |--List:元素是有序的,元素可以重复,因为该集合体系有索引;
 |--Set: 元素是无序的,元素不可以重复
 
 List集合:特有方法,凡是可以操作角标的方法都是该体系的特有方法
 增:add(index,element)
     addAll(index ,Collection)
 删:remove(index)
    改:set(index,element)
    查:get(index)
        subList(from,to)
        listIterator()
    List集合特有的迭代器,ListIterator是Iterator的子接口,在迭代时,不可以通过
集合对象的方法操作集合中的元素,因为会发生并发修改异常ConcurrentModificationException,
所以在迭代器时,只能用迭代器的方法操作元素,可是Iterator的方法有限,如果想要其他添加等,
需要ListIterator. hasPreviouse()逆向遍历 
*/
import java.util.*;
class ListDemo
{
 public static void sop(Object obj)
 {
  System.out.println(obj);
 }
 
 public static void main(String[] args){
  ArrayList al= new ArrayList();
  al.add("zhang");
  al.add("zhang1");
  al.add("zhang2");
  ListIterator is=al.listIterator();
  while(is.hasNext())
  {
   Object obj=is.next();
   if(obj.equals("zhang"))
    is.set("hah");
  }
  sop(al);
 }
}

猜你喜欢

转载自blog.csdn.net/qq_37042434/article/details/79876068