请写出 使用ArrayList和Vector最简单的列子
请写出 使用HashMap和Hashtable最简单的列子

解决方案 »

  1.   

    ArrayList:是用于非线程同步的,因为它速度快,效率高
    Vector:用于线程同步的,因为它速度慢,但是安全
    HashMap:是用于非线程同步的,因为它速度快,效率高,同时允许设置值为null
    Hashtable:用于线程同步的,因为它速度慢,但是安全
      

  2.   

    楼主这种例子书上有很多啊,百度google一下也会有很多
      

  3.   

    可以上google百度一下
    例子很多的
      

  4.   

    你站内搜索,csdn上这种帖子也有很多的
      

  5.   

    他们都是一个容器 很简单的  你就对着API文档  创建一个  然后往里面加东西  然后输出一下就可以了  import java.util.*;public class TestArrayList{
    public static void main(String args[]){
    ArrayList<String> al = new ArrayList<String>();

    al.add("a");
    al.add("c");
    al.add("b");

    for(String s : al)
       System.out.print(s +" ");
    }
    }
      

  6.   

    package ttt;import java.util.ArrayList;
    import java.util.Arrays;public class Sort { public Sort() {
    super();
    // TODO 自动生成构造函数存根
    } public void sort(ArrayList al) {
    Object[] obj = new Object[al.size()];
    for (int i = 0; i < obj.length; i++) {
    obj[i] = al.get(i);
    System.out.println(obj[i]);
    } Arrays.sort(obj);
    System.out.println("adjflkajfkljsajfjdkf");
    for (int i = 0; i < obj.length; i++) {
    System.out.println(obj[i]); }
    } public static void main(String[] args) {
    ArrayList al = new ArrayList();
    al.add(new dtp("stl", 35));
    al.add(new dtp("ssl", 75));
    al.add(new dtp("lss", 20));
    al.add(new dtp("sls", 30));
    al.add(new dtp("sll", 35));
    al.add(new dtp("lsl", 98));
    new Sort().sort(al); }
    }
      

  7.   

    package ttt;import java.util.Date;public class MailSendDateBean implements Comparable<Date> { private String msgID = ""; private Date sentDate = null; public MailSendDateBean(String msgID, Date sentDate) {
    super();
    this.msgID = msgID;
    this.sentDate = sentDate;
    } public String getMsgID() {
    return msgID;
    } public void setMsgID(String msgID) {
    this.msgID = msgID;
    } public Date getSentDate() {
    return sentDate;
    } public void setSentDate(Date sentDate) {
    this.sentDate = sentDate;
    } public int compareTo(Date date) {
    return 0;
    } public String toString() {
    return this.msgID + "   ";//+ this.sentDate;
    }
    }
      

  8.   

    package ttt;public class dtp implements Comparable { public dtp(String name, int num) {
    super();
    // TODO 自动生成构造函数存根
    this.name = name;
    this.num = num;
    } public dtp() {
    super();
    // TODO 自动生成构造函数存根
    } private String name = null;
    private int num = 0; public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } public int getNum() {
    return num;
    } public void setNum(int num) {
    this.num = num;
    } public int compareTo(Object o) {
    // TODO 自动生成方法存根
    int a = this.num;
    int b = ((dtp) o).num;
    return ((a == b) ? 0 : ((a < b) ? 1 : -1));
    } public String toString() {
    return this.name + "   " + this.num;
    }
    }