Tuesday, 9 December 2014

Java : Collection Framework : Vector (Get first and last Object)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=Z41SkCKINi0&list=UUhwKlOVR041tngjerWxVccw

VectorExample.java
import java.util.Vector;

/*
 *  Example of firstElement(), lastElement() method. 
 */
public class VectorExample
{
    public static void main( String[] args )
    {
        Vector<Integer> vector = new Vector<Integer>();

        vector.add(10);
        vector.add(20);
        vector.add(30);
        vector.add(40);
        vector.add(50);

        System.out.println("vector  : " + vector + "\n");

        /*
         * Returns the first component (the item at index 0) of this vector.
         */

        Integer firstElement = vector.firstElement();
        System.out.println("firstElement : " + firstElement);

        /*
         * Returns the last component of the vector.
         */
        Integer lastElement = vector.lastElement();
        System.out.println("lastElement : " + lastElement);

    }
}

Output
vector  : [10, 20, 30, 40, 50]

firstElement : 10
lastElement : 50


To Download VectorDemoGetFirstlast Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/VectorDemoGetFirstlast.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge