------- android培训、java培训、期待与您交流! ----------
一.集合框架结构图
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
二..集合中元素的增删改查
示例代码:
package com.yijie.collection;
import java.util.ArrayList;
public class Test1 {
public static void main(String[] args) {
//创建collection接口实现类ArrayList的对象
ArrayList al = new ArrayList();
//创建一个String类对象.
String st1 = "string1";
String st2 = "string2";
String st3 = "string3";
String st4 = "string4";
String st5 = "string5";
//向ArrayList集合对象中添加String类对象.
al.add(st1);
al.add(st2);
al.add(st3);
al.add(st4);
//在某个位置上添加元素
add(1, st5);
//删除某个位置上的元素
remove(1)
//打印集合
System.out.println(al);
//获取集合中的元素个数
int num=al.size();
System.out.println(num);
//删除集合中的某个元素。
al.remove(st1);
System.out.println(al);
//清空集合中的元素。
al.clear();
//获取某个位置上的元素
al.get(0);
}
}