Java Vector.add(E e) Method

 Posted On  | Yashwant Chavan 

In this tutorial, you will learn about Java Vector.add(E e) method. It is used to append the specified element to the end of this Vector.

syntax

Appends the specified element to the end of this Vector.

boolean java.util.Vector.add(E e)

Parameters

e - element to be appended to this Vector.

Return

returns true, if element added successfully, otherwise returns false value.

Java example to append element to the Vector

  • Create Vector instances using new Vector().
  • Add some elements in the Vector.
  • Print Vector elements.
package com.technicalkeeda.app;

import java.util.Vector;

public class VectorAddElement {
    public static void main(String[] args) {

        Vector < String > colors = new Vector < String > ();
        System.out.println("Vector Elements before:- " + colors);
        colors.add("Red");
        colors.add("Green");
        colors.add("Blue");
        colors.add("Pink");
        colors.add("Yellow");
        colors.add("Orange");
        System.out.println("Vector Elements after:- " + colors);
    }
}

Output

Vector Elements before:- []
Vector Elements after:- [Red, Green, Blue, Pink, Yellow, Orange]


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0310 seconds.