I've searched as far as I can look and I'm struggling to find an answer to this question.. I have an Iterable object and I want to modify each item in it (I do NOT want to add to it) with a new value. I've tried
for (T e : list) 
{
    e = a.get(index);
    System.out.println(e);
    index--;
}
to modify it but that obviously didn't work, because it is a foreach loop. Can someone show me what I'm doing wrong with this code? (The idea is that i'm trying to reverse my Iterable's item order.)
public class LinkedList<T>
{
     Iterable<T> list;
     public LinkedList() {} //create an empty list
     public LinkedList(Iterable<T> iterable)
     {
         list = iterable;
     }
     @SuppressWarnings("unchecked")
     public Iterable<T> reverse()
     {
         Integer size = size();
         List<T> a = new ArrayList<T>();
         Integer index = size - 1;
         for (T e : list) 
         {
             a.add(e);
         }
         Iterator iterator = list.iterator();
         while (iterator.hasNext()) 
         {
             T element = (T)iterator.next();
             element = a.get(index);
             System.out.println(element);
             index--;
         }
         return list;
     }
}
 
    