Circular collection with 2 values
Circular collection with 2 values Is there some collection in Java in which I can put 2 objects and then by calling a method on one to return the other one? Example: myColection [o1,o2] myCollection.getNext(o1) to retunr o2 and viceversa. No. What are you trying to do? What collections did you look at? – user1803551 Sep 2 at 18:12 Such a collection wouldn't make much sense and it would be trivial to roll something yourself (it would be a simple if(param == o1) return o2; else if(param == o2) return o1; else throw Exception; anyways). - What's the use case for that? – Thomas Sep 2 at 18:18 if(param == o1) return o2; else if(param == o2) return o1; else throw Exception; trying to hit play() on this 2 element collection of 2 players so that each player can move one after another – Daniel Sep 2 at 18:48 In that case I'd recommend rolling your own solution as next() will probably not be the only thing you'll need. – Thomas Sep 3 at 9:09 next(