Tuesday, 26 May 2015

How to insert element in vector

import java.util.Vector;

public class AddElement {
    public static void main(String[] args) {
        Vector<String> vector = new Vector<String>();
        //add element in vector
        // print vector
        System.out.println("Vector = "+vector);

         * Inserts the specified element at the specified
         * position in this Vector.
        vector.add(1, "java");
        System.out.println("vector after insert element = "+vector);


Vector = [cricket, hockey, football, tennish]

vector after insert element = [cricket, java, hockey, football, tennish]

No comments:

Post a Comment