java - clone() method in LinkedList -


i learning java , going on collections framework currently. trying out api methods linkedlist , facing problem clone() method. below 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 compile program, 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 lookup unsuccessful in finding reason. wrong program??

list doesnt have clone method. change to:

linkedlist<string> color1list = new linkedlist<string>(); 

if want leave list, you'll have little ugly like:

list clonedlist = (linkedlist) ((linkedlist) color1list).clone(); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -