Hi. I was wondering how I could replace objects in a list without using a single loop. Here's what I have in terms of algorithm; but, I don't know how to implement.:
replace(List list, oldObject, newObject)

1. if the first element in list is not null 
2        if the old Object == (the object in list)
3             new object replaces old Object
4        replace(list, oldObject, newObject)

Ps. I know the == is not allowed when comparing objects, its just pseduo code

I don't know how to traverse through the list without a for loop. Could I use iterator?

If you don't mind me asking, is there a particular reason why you do not want to use an iteration? Is this a class assignment, or just curiosity on your own part?

Also, I assume that this is not a class implementing the standard Java List interface, so we would need more information about the list class you are using. Could you post the code for the class, please?

I am interested; but, this is a class assignment. I understand iteration would be faster/efficient. I am practicing recursion method writing. THis uses the List interface. I'm not asking for code. I know the algorithm, I just don't know how to traverse through the list without using loops.