LinkedList copy
In this chapter you will learn:
Shallow copy of a LinkedList
Object clone()
Returns a shallow copy of this LinkedList.
Shallow copy means this LinkedList and its clone shares the same object reference to their elements.
import java.util.LinkedList;
//from j a v a 2 s .com
public class Main{
public static void main(String args[]) {
LinkedList<String> ll = new LinkedList<String>();
ll.add("B");
ll.add("ja v a2s.com");
ll.addLast("E");
ll.add("F");
System.out.println("Original contents of ll: " + ll);
LinkedList newList = (LinkedList)ll.clone();
System.out.println(newList);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » List