I am trying to deep copy list of objects from a global arraylist and return all the objects in my return function as below
ArrayList<Objects> list = new ArrayList<Objects>();
public Objects copy() {
Objects copied = new Objects();
ArrayList<Objects > newList = new ArrayList<Objects>();
for(Objects objs : list){
newList.add(objs);
}
for(int i=0; i<newList.size(); i++ ){
copied = newList.get(i);
}
return copied;
}
But this function only returns the very last element in the list. How do I make the function return all values? For eg if there are 3 objects in the global list my function should return all the 3 values.
Also I do not want my function return type to be an ArrayList<Objects> ie I dont want to return an ArrayList of Objects
Is this possible? If so what am I missing?
ArrayList<Objects>? If you returnObjectsit will only be one element. So what do you want to return?copied.