Hi,
On Tue, Apr 1, 2008 at 1:25 AM, Pedro Pedruzzi <[EMAIL PROTECTED]> wrote:
> I have a java.util.Set and I'd like to do a iteration like "for each
> to distinct pair of elements" do something. In this case I don't care
> for the ordering of the pair. A most precise way would be: "for each
> subset of size 2" do something.
>
> Do the Apache Commons Collections provide some class to do this?
I'm not sure if Commons Collections has something like that, but you
should be able to do it quite easily with just a few lines of code:
Set set = ...;
Object[] objects = set.toArray();
for (int i = 0; i < objects.length - 1; i++) {
for (int j = i + 1; j < objects.length; j++) {
processPair(objects[i], objects[j]);
}
}
BR,
Jukka Zitting
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]