标签:opened more one public str [] closed hid color
1 package com.tn.collect; 2 3 import java.util.Enumeration; 4 import java.util.Iterator; 5 import java.util.Vector; 6 7 public class VectorDemo { 8 public static void main(String[] args){ 9 Vector<String> v=new Vector<String>(); 10 v.add("黄山"); 11 v.add("黄河"); 12 System.out.println(v); 13 System.out.println(v.size()); 14 15 Iterator<String> iterator=v.iterator(); 16 while(iterator.hasNext()){ 17 System.out.println(iterator.next()); 18 } 19 System.out.println("----------------------------"); 20 //比ArrayList多一种老的遍历: 21 Enumeration<String> e=v.elements(); 22 while(e.hasMoreElements()){ 23 System.out.println(e.nextElement()); 24 } 25 26 //ArrayList是线程不安全的,Vector是线程安全的。 27 } 28 }
运行结果:
[黄山, 黄河]
2
黄山
黄河
----------------------------
黄山
黄河
标签:opened more one public str [] closed hid color
原文地址:http://www.cnblogs.com/xiongjiawei/p/6602534.html