【3】List
1. 继承Collection,有序,允许重复,并引入index (定义了面向位置的操作方法)
2. 常用的方法:
void add ( int index, Object o )
Object get ( int index )
int indexOf ( Object o )
Object remove ( int index )
Object set ( int index , Object o )
List subList ( int fromIndex , int toIndex )
2. ArrayList
3. LinkedList 增添了处理列表两端元素的方法 (可当做Stack 或 Queue)
【4】Map
1. 键值对,常用的方法如下:
增改类:
Object put ( Object key , Object value )
Object remove ( Object key )
void putAll ( Map mapping )
void clear ( )
查询类:
Object get ( Object key )
boolean containsKey ( Object key )
boolean containsValue ( Object value )
int size ( )
boolean isEmpty ( )
转换成键或值的集合视图:
public Set keySet ( )
public Collection values ( )
public Set entrySet ( ) // 返回的Set 枚举后可用来实现 Map.Entry 接口
例如:
HashMap mapping = new HashMap ( ) ;
// put elements int to the map
…
Set entrySet = mapping.entrySet ( );
Iterator it = entrySet . iterator ( ) ;
while ( it.hasNext ) {
Map.Entry entry = ( Map.Entry ) it.next( );
System.out.print ( entry.getKey ( ) + " : " ) ;
System.out.println ( entry.getValue( ) );
}
2. HashMap
3. TreeMap