Groovy 二维数组组合
我有一个2D数组,看起来像[[1,2,3],[10,11]]。我想获得下一个组合:[[1,2,3,10],[1,2,3,11]]。这个想法是从左数组中获取所有值,并将其与右数组中的每个值结合。我尝试过开箱即用的方法(例如Compinations(),置换()获得预期的结果,但没有任何成功。请帮忙。
I have a 2D array which looks like [[1, 2, 3], [10, 11]]. I want to get the next combinations: [[1, 2, 3, 10], [1, 2, 3, 11]]. The idea is to take all values from left array and combine it with each value from right array. I've tried different Groovy out of the box methods like combinations(), permutations() to get the expected result, but without any success. Please, help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不简单:
Why not simply:
如果有人可以作弊...将第一个列表嵌套到另一个列表中可以让我们仍然使用
.combinations()
:现在,如果您无法像那样存储值,您仍然可以使更改部分代码。所有这些都假设该列表只是一对。
我相信有更少的非正统方法可以做到这一点,但这是一个快速而肮脏的解决方案。
If one can cheat... Nesting the first list into another list can let us use
.combinations()
still:Now, if you can't store the values like that, you can still still make the change part of your code. All this assumes that the list is just a pair.
I believe there are less unorthodox ways of doing it, but that's a quick and dirty solution.