09 April 2012

Create a Vector having Integer objects. Copy the Vector elements into an Array and display the Array elements.



    import java.util.Vector;
    public class CopyElementsOfVectorToArrayExample{
    public static void main(String[] args) {

    //create a Vector object
    Vector v= new Vector();

    //Add elements to Vector
    v.add("1");
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");

    //declare an array to hold elements of Vector
    Object[] objArray=new Object[5];
    v.copyInto(objArray);

    //display contents of Object array
    System.out.println("Vector elements are copied into an Array.Now Array Contains..");

    for(int index=0;index<objArray.length;index++)
    System.out.println(objArray[index]);
    }
    }


0 comments:

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;