Friday 30 May 2014

ArrayList : clone : Clone the LinkedList

public Object clone()
Returns a shallow copy of this LinkedList.

import java.util.*;

class ArrayListClone{
 public static void main(String args[]){
  ArrayList<Integer> myList;
  Object cloneList;
  
  myList = new ArrayList<> ();
  
  /* Add Elements to myList */
  myList.add(10);
  myList.add(20);
  myList.add(30);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
  
  cloneList = myList.clone();
  System.out.println("Elements in cloneList are");
  System.out.println(cloneList);
 }
}

Output
Elements in myList are
[10, 20, 30]
Elements in cloneList are
[10, 20, 30]

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment