For a given Collection<Object> aCollection
, How do I build an ArrayList<OrderedCouple<Object>>
with all possible permutations of couples in aCollection
(except self-coupling).
For instance, say aCollection
is a Set<Team>
containing teamA
, teamB
and teamC
, and OrderedCouple
is instead a class Game<Team>
which constructor receives two team, the host and the guest as arguments.
I want to build an ArrayList
of all possible Game
s between Team
s. that is, the ArrayList
will be the group {new Game(teamA, teamB), new Game(teamA, teamC), new Game(teamB, teamA), new Game(teamB, teamC), new Game(teamC, teamA), new Game(teamC, teamB)}
in a random order.
I can't think of a faster way than this:
prints something like this: