I am learning java and going over the collections framework currently. I am trying out the API methods for LinkedList and am facing problem with the clone() method. Below is my code
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ListIterator;
import java.util.LinkedList;
public class LinkedListTest
{
public static void main(String[] args)
{
String[] colors1 = {"Red", "Blue"};
List<String> color1List = new LinkedList<String>();
for(String color:colors1)
color1List.add(color);
List clonedList = (LinkedList) color1List.clone();
}
}
When I compile this program, I get the following Error:
LinkedListTest.java:51: cannot find symbol
symbol : method clone()
location: interface java.util.List<java.lang.String>
List<String> clonedList = (LinkedList<String>)color1List.clone();
^
1 error
I tried to lookup but was unsuccessful in finding any reason. What is wrong with the program??