Thursday, February 25, 2016

Vector Cast Inwards Java

| Thursday, February 25, 2016
  • Vector cast inwards coffee implements List interface of collection framework.
  • Vector cast is synchronized.
  • If you lot don't know size of array therefore you lot tin piece of employment vector cast every bit size of vector tin grow together with shrink every bit per adding together with removing items.
  • As vector cast is synchronized, It volition rank pitiable performance on add, delete, update together with search operations.
  • Elements of vector tin live accessed using it's integer index.
Vector cast inwards coffee implements List interface of collection framework Vector Class In Java

Important method of vector class
  • void addElement(Object element) : It volition add together specified chemical component at destination of vector.
  • int capacity() : It volition supply the electrical flow capacity of vector.
  • int size() : This method volition supply electrical flow size of vector.
  • void setSize(int size) : It volition gear upwards size of vector using given size value.
  • boolean contains(Object element) : It volition supply truthful if specified chemical component acquaint inwards vector. Else it volition supply false.
  • boolean containsAll(Collection c) : It volition supply truthful if vector contains all values of given collection c.
  • Object elementAt(int index) : It volition supply chemical component which is located at specified index of vector.
  • Object firstElement() : It volition supply get-go chemical component of vector.
  • Object lastElement() : It volition supply concluding chemical component of vector.
  • Object get(int index) : It volition supply chemical component located at the specified index of vector.
  • boolean isEmpty() : It volition supply truthful if vector is empty.
  • boolean removeElement(Object element) : It volition take given chemical component from vector.
  • boolean removeAll(Collection c) : It volition take all elements of collection c from vector.
  • void setElementAt(Object element, int index) : It volition gear upwards specified chemical component at given index of vector.
Bellow given sample plan volition demo you lot how to piece of employment vector cast together with it's unlike methods.

Vector cast example
package JAVAExamples;  import java.util.Enumeration; import java.util.Vector;  populace cast VectorExample {  populace static void main(String args[]) {   //Initial vector capacity is 2. Increment it past times 2 when required.   Vector 5 = novel Vector(2,2);   System.out.println("Initial capacity of vector : "+v.capacity());   v.addElement("one");   v.addElement("two");   v.addElement("three");     System.out.println("Capacity of vector subsequently adding 3 elements inwards vector : "+v.capacity());    //Get size of vector.   System.out.println("Size of vector : "+v.size());    //Get get-go chemical component of vector.   System.out.println("First chemical component of vector : "+v.firstElement());      //Get concluding chemical component of vector.   System.out.println("Last chemical component of vector : "+v.lastElement());      //Add novel chemical component inwards vector.   v.add(2, "New Element");      //Print all elements of vector using Enumeration.   Enumeration vEnum = v.elements();   System.out.print("Current vector elements : ");   while(vEnum.hasMoreElements()){    System.out.print(vEnum.nextElement() + ", ");   }      System.out.println();      //Check if vector is empty.   System.out.println("Vector is empty? : "+v.isEmpty());    } }

Output :
Initial capacity of vector : 2 Capacity of vector subsequently adding 3 elements inwards vector : four Size of vector : 3 First chemical component of vector : 1 Last chemical component of vector : 3 Current vector elements : one, two, New Element, three,  Vector is empty? : false

Above instance shows you lot usage of by together with large used methods of vector class. http://www.feedbooks.com/user/4455042/profile

Related Posts