Java ArrayList clone Example
ArrayList class clone method example. This example shows you how to use clone method.
ArrayList class clone method example.public Object clone() Returns a shallow copy of this ArrayList instance. (The elements themselves are not copied.)
Here is the code
/**
* @ # Clear.java
* A class repersenting use to clear() method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class Clone {
public static void main(String args[]) {
ArrayList arrlist = new ArrayList();
int i = 0;
String str = "Rose India";
//Add the specified element to the end of this list.
arrlist.add(i);
arrlist.add(str);
System.out.println("arrlist = " + arrlist);
//Creat clone of the Arraylist
List list =(ArrayList) arrlist.clone();
System.out.println("list = " + list);
}
} |
Output
arrlist = [0, Rose India]
list = [0, Rose India]
|
|