本帖最后由 王琪 于 2014-3-11 13:03 编辑
- java.util.Enumeration ev=v3.elements();//这里不太会 v3.elements()返回枚举?Enumeration Iterator 不一样?
- //得到描述myDataStruct类型对象的enumeration对象
Enumeration myEnumeration =myDataStruct.getEnum(); 和v3.elements()不一样吗? - v1.subList(1, 3).clear();//这里也不明白 v1改变了吗????v1=[1,2,3,4,5] 变了[1, 4, 5]为啥?
- <b>package dom;
- import java.io.*;
- import java.util.*;
- public class Text {
- public static void main(String[]args){
- Vector v1=new Vector();//v1=[],size=0,capacity=10
- for(int j=1 ;j<=5 ;j++ )
- v1.addElement(new Integer(j));//v1=[1,2,3,4,5],size=5,capacity=10
- System.out.println("v1="+v1);
- Integer i=new Integer(3);
- System.out.println(v1.indexOf(i)+" "+v1.indexOf(i,4));//2 -1
- System.out.println(v1.contains(i)+" "+v1.lastIndexOf(i));//true 2
- Vector v2=new Vector(3,4);//v2=[],size=0,capacity=3
- for(int j=4 ;j<8 ;j++ )
- v2.addElement(new Integer(j));//v2=[4,5,6,7,8],size=5,capacity=7
-
- v2.ensureCapacity(9);//v2=[4,5,6,7,8],size=5,capacity=11
-
- Vector v3=new Vector(2);//v3=[],size=0,capacity=2
- v3.setSize(4);//v3=[null,null,null,null]
- v3.setElementAt(new Integer(9), 1);//v3=[null,9,null,null]
- v3.setElementAt(new Integer(5), 3);//v3=[null,9,null,5]
- v3.insertElementAt(v3.elementAt(3),1);//v3=[null,5,9,null,5],size=5,capacity=8
-
- v3.ensureCapacity(9);//v3=[null,5,9,null,5],size=5,capacity=16
- v3.removeElement(new Integer(9));//v3=[null,5,null,5]
- v3.removeElementAt(v3.size()-2);//v3=[null,5,5]
- java.util.Enumeration ev=v3.elements();//这里不太会 v3.elements()返回枚举?Enumeration Iterator 不一样?
- //得到描述myDataStruct类型对象的enumeration对象
- //Enumeration myEnumeration =myDataStruct.getEnum();
-
- while(ev.hasMoreElements()){
- System.out.println(ev.nextElement()+" ");
- }
- System.out.println();
- v3.removeElementAt(0);//v3=5,5]
- v3.addAll(v1);//v3=[5,5,1,2,3,4,5];
- v3.removeAll(v2);//v3=[1,2,3]
- v3.addAll(2, v1);//v3=[1,2,1,2,3,4,5,3]
- v3.retainAll(v2);//v3=[4,5]
-
- v1.subList(1, 3).clear();//这里也不明白 v1改变了吗????v1=[1,2,3,4,5] 变了[1, 4, 5]为啥?
- System.out.println(v1);
- }
- }
- </b>
复制代码 输出
- v1=[1, 2, 3, 4, 5]
- 2 -1
- true 2
- null
- 5
- 5
- [1, 4, 5]
复制代码
|