java java的排列/组合库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12013584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
permutations/combinatorics library for java?
提问by Paul Sanwald
I am looking for a library for java that will generate all possible order permutations of a set. The only library I can find is combinatoricslib on google code. I find it very hard to believe this is the only java library that does this, and am quite frankly very surprised by this.
我正在寻找一个 java 库,它将生成一个集合的所有可能的顺序排列。我能找到的唯一库是google code 上的 combinatoricslib。我发现很难相信这是唯一一个这样做的 Java 库,坦率地说,我对此感到非常惊讶。
Is there anything in the JDK, or apache commons math, or another library, that provides this same functionality?
JDK、apache commons math 或其他库中是否有提供相同功能的内容?
I am happy to use combinatoricslib, I just can't believe that's the only option, other than writing the algorithm myself, which admittedly is not that difficult, but neither is .isBlankOrNull(), and apache commons includes that.
我很高兴使用combinatoricslib,我简直不敢相信这是唯一的选择,除了自己编写算法,诚然这并不难,但.isBlankOrNull() 也不是,而且apache commons 包括它。
采纳答案by Cratylus
回答by Oliver Coleman
There's the PermutationIteratorclass in the Apache Commons Collection library version 4. It accepts a generic Collection and provides an Iterator that iterates over all permutations of the elements in the Collection (each call to next() on the Iterator provides an ordered List).
在 Apache Commons Collection 库版本 4 中有PermutationIterator类。它接受一个泛型 Collection 并提供一个迭代器来迭代集合中元素的所有排列(每次调用 Iterator 上的 next() 都提供一个有序列表)。
I just realised version 4 of the Collection library was only released on 2013-11-27. Version 3 doesn't provide a utility for permutations. V4 "represents a major revamp of collections by supporting new language features introduced with Java 1.5, mainly support for generics."
我刚刚意识到 Collection 库的第 4 版仅在 2013 年 11 月 27 日发布。版本 3 不提供用于排列的实用程序。V4 “通过支持 Java 1.5 引入的新语言特性,主要是对泛型的支持,代表了集合的重大改进。”