首页 > 其他 > 详细

Vector ArrayList

时间:2021-09-04 05:17:30      阅读:25      评论:0      收藏:0      [点我收藏+]

 

 

Vector vlist = new Vector();
vlist.add(1);
vlist.add("abc");
vlist.addElement("456");
vlist.add(3,"eee");
vlist.add(4,"eee");
vlist.add(5,"eee");
vlist.add(6,"eee");
vlist.add(7,"eee");
vlist.add(8,"eee");
vlist.add(9,"eee9");
vlist.add(10,"ee10");
System.out.println(" vlist capacity" + vlist.capacity());
int r = vlist.indexOf("eee");
System.out.println(" vlist r indexof" + r);
Enumeration vEnum = vlist.elements();
while(vEnum.hasMoreElements()) {
System.out.println("vlist="+vEnum.nextElement());

}
ArrayList arlist = new ArrayList();
arlist.add(1);
arlist.add("abc");
arlist.add("456");
arlist.add(3,"eee");
arlist.add(4,"eee");
arlist.add(5,"eee");
arlist.add(6,"eee");
arlist.add(7,"eee");
arlist.add(8,"eee");
arlist.add(9,"eee9arlist");
arlist.add(10,"ee10");
System.out.println(" arlist size" + arlist.size());
for (int i = 0; i < arlist.size(); i++) {
System.out.println("arlist="+arlist.get(i));

}

}

vlist capacity20
vlist r3
vlist=1
vlist=abc
vlist=456
vlist=eee
vlist=eee
vlist=eee
vlist=eee
vlist=eee
vlist=eee
vlist=eee9
vlist=ee10
arlist size11
arlist=1
arlist=abc
arlist=456
arlist=eee
arlist=eee
arlist=eee
arlist=eee
arlist=eee
arlist=eee
arlist=eee9arlist
arlist=ee10


区别
  1. ArrayList在内存不够时默认是扩展50% + 1个,Vector是默认扩展1倍。
  2. Vector提供indexOf(obj, start)接口,ArrayList没有。

 

Vector ArrayList

原文:https://www.cnblogs.com/xiaohuizhenyoucai/p/15223439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!