Vector clone() in Java

clone(): This method is available in java.util.Vector class of Java.

Syntax:

Object java.util.Vector.clone()

This method returns a clone of this vector.

Note: The copy will contain a reference to a clone of the internal data array, not a reference to the original internal data array of this Vector object.

Parameters: NA

Returns: a clone of this vector.

Exceptions: NA

Approach

Java

import java.util.Vector;

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

        Vector<String> vector = new Vector<>();

        vector.add("Hello");
        vector.add("Java");
        vector.add("C++");
        vector.add("Program");

        System.out.println(vector.clone());
    }
}

Output:

[Hello, Java, C++, Program]


No comments:

Post a Comment