Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

recursive combinations

807580Apr 25 2010 — edited Apr 26 2010
I'm working on this project and I need some help. What I've got is an ArrayList of objects each of which consists of (name, x coordinate, y coordinate). What I need to do is generate a combination of all possible combinations of objects and print their name. The method in which I am trying to write takes a subset size. For example say I've got an ArrayList of the following:
[a,b,c,d,e]
The method will receive a subset size that is specified by the user, we'll go with 3 for this example. I need to print the following:
a,b,c
a,b,d
a,b,e
a,c,d
a,c,e
a,d,e
b,c,d
b,c,e
b,d,e

I figure that recursion is a must because if the subset size is set for anything other than what I intend my for statements would not work. I just cannot figure out how I would do this. I've worked with recursion before but am stumped. Any help would be greatly appreciated.

Thank you!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2010
Added on Apr 25 2010
4 comments
449 views