Vector: firstElement() : Vector : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.util   » [  Vector  ]   
 



Vector: firstElement()

/**
 *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>(32);

    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.  Vector: addElement(E e)
2.  Vector: elementAt(int index)
3.  Vector: contains(Object obj)
4.  Vector: capacity()
5.  Vector: elements()
6.  Vector: indexOf(Object o)
7.  Vector: insertElementAt(E obj, int index)
8.  Vector: lastElement()
9.  Vector: size()
10.  Save Vector to File
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.