Vector和Hashtable的使用:

来源:互联网 发布:淘宝个人交易信息买卖 编辑:程序博客网 时间:2024/05/17 08:15

Vector例子:可以往向量中添加各种类型的数据

 

class MyVector extends Vector
...{
    public MyVector()
    ...{
        super(1,1);
    }
    public void addInt(int i)
    ...{
        addElement(new Integer(i));
    }
    public void addString(String s)
    ...{
        addElement(s);
    }
    public void printVector()
    ...{
        Object o;
        int len=size();
        System.out.println("the size of Vector is :"+len);
        for(int i=0;i<len;i++)
        ...{
            o=elementAt(i);
            System.out.println(o.toString());
        }
    }
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/DavidLove/archive/2006/10/10/1329337.aspx

 

Hashtable例子:统计网站访问次数,根据用户名来统计

Hashtable userTable=new Hashtable();
public int getCount(String userName)
...{
     Integer count=(Integer)userTable.get(userName);
     if(count==null)
     ...{
          int nowCount=count.IntValue()+1;
          userTable.put(userName,new Integer(nowCount));
          return nowCount;
     }
     userTable.put(userName,new Integer(1));
     return 1;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/DavidLove/archive/2006/10/10/1329337.aspx