列表的可能组合
我有一个对象数组列表,我想创建所有可能的组合(根据一组简单的规则)。存储在列表中的每个对象都包含一个小队编号和一个字符串。这是我存储的典型列表的示例:
0: 1, A
1: 1, B
2: 2, A
3: 2, B
4: 3, C
5: 3, D
6: 4, C
7: 4, D
我想要获取每个小队编号只能出现一次的所有组合,例如: (1,A),(2,A),(3,C),( 4,C) 那么下一个组合将是 (1,A),(2,A),(3,C),(4,D)。 我将如何在java中解决这个问题?通常我会使用嵌套循环,但事实上它全部存储在一个列表中,这让我的事情变得复杂。
谢谢, 脱漆剂
I have an arraylist of objects that I want to create all possible combinations (according to a simple set of rules). Each object that is stored in the list holds a squadNumber and a string. Here is an example of a typical list I am storing:
0: 1, A
1: 1, B
2: 2, A
3: 2, B
4: 3, C
5: 3, D
6: 4, C
7: 4, D
I want to get all the combinations where each squadNumber can only be present once, for example: (1,A),(2,A),(3,C),(4,C) then the next combination would be (1,A),(2,A),(3,C),(4,D).
How would I go about this in java? Usually I would use a nested loop, but the fact that it's all being stored in one list complicates things for me.
Thanks,
paintstripper
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑
算法如下:
另一个小队 2 的列表,等等。
代码
EDITED
Algorithm is following:
another list for squads 2, etc.
Code