Thursday, 11 December 2014

Java : Collection Framework : Vector (toArray)


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

VectorExample.java
import java.util.Vector;

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

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

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

        /*
         * Returns an array containing all of the elements in this Vector in the
         * correct order.
         */

        Object[] objArray = vector.toArray();

        for( Object object : objArray )
        {
            Integer value = (Integer) object;
            System.out.println(value);
        }

    }
}

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

20
30
40
50

To Download VectorDemoToArray Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoToArray.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