Vector is the implementation class of the list interface, supports all functions of the list interface, the vector class is an array-based implementation of the list class, in the internal encapsulation of a dynamic,
Allow redistribution of the object[] array, vector is thread-safe, without the need for a program to ensure the synchronization of the collection.
The following is a description of the methods used by the vector class:
public class Main {public static void main (string[] args) {vector vector=new vector ();/* * Adds the specified element to the end of this vector. */vector.add ("Bill");//output: [Bill]system.out.println (vector);/* * Insert the specified element at the specified position in this vector. Moves the element that is currently at that location (if any) and all subsequent elements to the right (adding 1 to its index). * If the index is out of range (Index < 0 | | index > Size ()), throw arrayindexoutofboundsexception exception */vector.add (1, "Jack");//output: [Bill, Jac K]system.out.println (vector); List list=new ArrayList (); List.add (1); List.add (2);/* Adds all elements in the specified Collection to the end of this vector, adding the elements in the order returned by the specified Collection iterator. * If the specified Collection is modified during operation, the behavior of this operation is indeterminate (this means that if the specified Collection is this vector, * and this vector is not NULL, the behavior of this call is indeterminate). * If the specified collection is null thrown NullPointerException exception */vector.addall (list);//output: [Bill, Jack, 1, 2]system.out.println ( Vector); List List1=new ArrayList (); List1.add ("Hello");/* * Inserts all elements from the specified Collection into this vector at the specified location. Moves the element that is currently at that location (if any) * and all subsequent elements to the right (increasing its index value). * New elements appear in the vector in the order that they are returned by the iterators that specify collection. * If the index is out of range (Index < 0 | | index > Size ()) throws ArrayIndexOutOfBoundsException Exception * If the specified collection is null, throws Nullpointer ExCeption Abnormal */vector.addall (0,list1);//output: [Hello, Bill, Jack, 1, 2]system.out.println (vector);/* Adds the specified component to the end of this vector, Increase its size by 1. If the size of the vector is larger than the capacity, increase its capacity. */vector.addelement ("Marray"); System.out.println (vector); */* Returns the current capacity of this vector. */system.out.println (Vector.capacity ());/* Returns a copy of the vector. The copy will contain a reference to a copy of the internal data array, instead of a reference to the original internal data array of this Vector object. */vector vector1= (Vector) Vector.clone () vector.add ("add");//output: Vector1--->[hello, Bill, Jack, 1, 2, Marray] System.out.println ("Vector1--->" +vector1);//output: Vector--->[hello, Bill, Jack, 1, 2, Marray, ADD] System.out.println ("Vector--->" +vector); */* Removes all elements from this vector. When this call returns, the vector will be empty (unless an exception is thrown). */vector1.clear ();//output: []system.out.println (Vector1);/* * Returns True if this vector contains the specified element. More precisely, * returns true if and only if this vector contains at least one element e that satisfies (o==null? E==null:o.equals (E)) *. */system.out.println (Vector.contains ("Word"));//output: false//output: TrueSystem.out.println (Vector.contains ("Marray")) ;/* Returns True if this vector contains the specified element. More precisely, * returns true if and only if this vector contains at least one element e that satisfies (o==null? E==null:o.equals (E)) *. */system.out.println (Vector.containsall (List1));//output: trueobject[] str = new object[10];/* * Copies the components of this vector into the specified array. The item at index k in this vector is copied to the component K of Anarray. * If the given array is null, throw the nullpointerexception exception * If the specified array is not large enough to hold all the components in this vector, throw the indexoutofboundsexception exception * If the component of this vector is not part of a run-time type that can be stored in the specified array, throw arraystoreexception exception */vector.copyinto (str);//output: [Hello, Bill, Jack, 1, 2, Marray, ADD, NULL, NULL, NULL]SYSTEM.OUT.PRINTLN (arrays.tostring (str)); */* Returns the component at the specified index. * If the index is out of range (Index < 0 | | | index >= size ()) throws ArrayIndexOutOfBoundsException exception */system.out.println ( Vector.elementat (1));//output: bill/* * An enumeration of components that return this vector. The returned enumeration object will generate all the items in this vector. * The first item generated is the item at index 0, then the item at index 1, and so on. */enumeration enumeration=vector.elements (); while (Enumeration.hasmoreelements ()) {//output: Hello Bill Jack 1 2 marray AD DSystem.out.println (Enumeration.nextelement ());}}}
Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/44087951 Emotional Control _
Java Learning Note 26