Vector: size() : Vector « java.util « Java by API






Vector: size()

  
/**
 *Output: 
Initial size: 0
Initial capacity: 3
First element: 1
Last element: 2
*/

import java.util.Vector;

public class MainClass {
  public static void main(String args[]) {

    // initial size is 3, increment is 2
    Vector<Integer> v = new Vector<Integer>(3, 2);

    System.out.println("Initial size: " + v.size());
    System.out.println("Initial capacity: " + v.capacity());

    v.addElement(1);
    v.addElement(2);

    System.out.println("First element: " + v.firstElement());
    System.out.println("Last element: " + v.lastElement());

    if (v.contains(3))
      System.out.println("Vector contains 3.");
  }
}

           
         
    
  








Related examples in the same category

1.new Vector(Collection c)
2.Vector: addElement(E e)
3.Vector: add(T e)
4.Vector: clear()
5.Vector: contains(Object obj)
6.Vector: containsAll(Collection c)
7.Vector: copyInto(Object[] anArray)
8.Vector: capacity()
9.Vector: elementAt(int index)
10.Vector: elements()
11.Vector: ensureCapacity(int minCapacity)
12.Vector: equals(Object o)
13.Vector: firstElement()
14.Vector: get(int index)
15.Vector: hashCode()
16.Vector: indexOf(Object o)
17.Vector: indexOf(Object o, int index)
18.Vector: insertElementAt(E obj, int index)
19.Vector: isEmpty()
20.Vector: iterator()
21.Vector: lastElement()
22.Vector: lastIndexOf(Object o)
23.Vector: lastIndexOf(Object o, int index)
24.Vector: listIterator()
25.Vector: remove(int index)
26.Vector: remove(Object o)
27.Vector: removeAllElements()
28.Vector: removeAll(Collection c)
29.Vector: removeElementAt(int index)
30.Vector: removeElement(Object obj)
31.Vector: retainAll(Collection c)
32.Vector: set(int index, Object element)
33.Vector: setSize(int newSize)
34.Vector: subList(int fromIndex, int toIndex)
35.Vector: toArray()
36.Vector: toArray(T[] a)
37.Save Vector to File