list接口及实现类

list接口及实现类

java.util 
接口 List<E>

所有超级接口:
Collection<E>,   Iterable<E>
所有已知实现类:
AbstractList,   AbstractSequentialList,   ArrayList,
  AttributeList,   CopyOnWriteArrayList,   LinkedList,
RoleList, RoleUnresolvedList,   Stack,   Vector
list接口方法:

方法摘要
 booleanadd(E e) 
          向列表的尾部添加指定的元素(可选操作)。
 voidadd(int index, E element) 
          在列表的指定位置插入指定元素(可选操作)。
 booleanaddAll(Collection<? extends E> c) 
          添加指定 collection 中的所有元素到此列表的结尾,顺序是指定 collection 的迭代器返回这些元素的顺序(可选操作)。
 booleanaddAll(int index, Collection<? extends E> c) 
          将指定 collection 中的所有元素都插入到列表中的指定位置(可选操作)。
 voidclear() 
          从列表中移除所有元素(可选操作)。
 booleancontains(Object o) 
          如果列表包含指定的元素,则返回 true
 booleancontainsAll(Collection<?> c) 
          如果列表包含指定 collection 的所有元素,则返回 true
 booleanequals(Object o) 
          比较指定的对象与列表是否相等。
 Eget(int index) 
          返回列表中指定位置的元素。
 inthashCode() 
          返回列表的哈希码值。
 intindexOf(Object o) 
          返回此列表中第一次出现的指定元素的索引;如果此列表不包含该元素,则返回 -1。
 booleanisEmpty() 
          如果列表不包含元素,则返回 true
 Iterator<E>iterator() 
          返回按适当顺序在列表的元素上进行迭代的迭代器。
 intlastIndexOf(Object o) 
          返回此列表中最后出现的指定元素的索引;如果列表不包含此元素,则返回 -1。
 ListIterator<E>listIterator() 
          返回此列表元素的列表迭代器(按适当顺序)。
 ListIterator<E>listIterator(int index) 
          返回列表中元素的列表迭代器(按适当顺序),从列表的指定位置开始。
 Eremove(int index) 
          移除列表中指定位置的元素(可选操作)。
 booleanremove(Object o) 
          从此列表中移除第一次出现的指定元素(如果存在)(可选操作)。
 booleanremoveAll(Collection<?> c) 
          从列表中移除指定 collection 中包含的其所有元素(可选操作)。
 booleanretainAll(Collection<?> c) 
          仅在列表中保留指定 collection 中所包含的元素(可选操作)。
 Eset(int index, E element) 
          用指定元素替换列表中指定位置的元素(可选操作)。
 intsize() 
          返回列表中的元素数。
 List<E>subList(int fromIndex, int toIndex) 
          返回列表中指定的 fromIndex(包括 )和 toIndex(不包括)之间的部分视图。
 Object[]toArray() 
          返回按适当顺序包含列表中的所有元素的数组(从第一个元素到最后一个元素)。
<T> T[]
toArray(T[] a) 
          返回按适当顺序(从第一个元素到最后一个元素)包含列表中所有元素的数组;返回数组的运行时类型是指定数组的运行时类型。


package com.Collectiom;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * list元素有序 元素可以重复 因为有索引!
 * @author 小明
 * list特有方法:
 * add(index,element)
 * addAll(index,Collection)
 * remove(index)
 * set(index,element)
 * get(index)
 * subList(from,index)
 * listIterator()
 */
public class ListDemo {
public static void main(String[] args) {
	List<String> list = new ArrayList<String>();
	list.add("a");
	list.add("b");
	list.add("c");
	list.add("d");
	//list.add(0, "f");
	//list.remove(0);
	System.out.println(list.get(0));
//	List<String> subList = list.subList(0, 2);
//	System.out.println(subList);
	ListIterator<String> listIterator = list.listIterator();
	while(listIterator.hasNext()){
		System.out.println("iterator------>"+listIterator.next());
	}
	
	List<String> list2 = new ArrayList<String>();
	list2.add("1");
	//list.addAll(list2);
	
	System.out.println(list);
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值