public
Object clone()
Returns
a shallow copy of this LinkedList.
import java.util.*; class LinkedListClone{ public static void main(String args[]){ LinkedList<Integer> myList; Object cloneList; myList = new LinkedList<> (); /* 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]
No comments:
Post a Comment