Can a Java function save a list before it's changed and recall it when needed? -


i have function , in newlist1 want have original l1 inserted @ beginning, , same true newlist2 , l2 respectively. suggestion how can it?

 public static list subcombo(list l1, list l2)     {     list newlist1= new linkedlist();     list newlist2= new linkedlist();         list list1= new linkedlist();      while (!l1.isempty())     {                            (object o: l2)         {             double product=1.0;              if ((double)hd(l1) == 0.0 && (double)hd(l2)!=0.0)             {                 product = (1-mysub(newlist1))*(double)hd(l2);                  list1.add(product);                      }                            if ((double)hd(l1)!=0.0 && (double)hd(l2) == 0.0)             {                 product= (1-mysub(newlist2))*(double) hd(l1);                 list1.add(product);              }              if ((double)hd(l2) == 0.0 && (double)hd(l1)==0.0)             {                                 product= (1-mysub(newlist1))*(1-mysub(newlist2));                 list1.add(product);              }              if ((double)hd(l1) != 0.0 && (double)hd(l2)!=0.0)             {                  product=(double)hd(l1)*(double)hd(l2);                           list1.add(product);              }                    l2=tl(l2);                       }          l1=tl(l1);       }        return list1; } 

as long, don't modify objects contained in containers, may copy lists before modification:

list newlist1 = new linkedlist(l1); list newlist2 = new linkedlist(l2); 

otherwise need make deep copy of lists. example


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -