permutations/combinatorics library for java? [closed]

混江龙づ霸主 提交于 2019-11-27 23:50:19

问题


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.

Is there anything in the JDK, or apache commons math, or another library, that provides this same functionality?

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.


回答1:


Have you checked Guava? It seems to offer permutations in Collections2

Class Collections2
permutations(Collection elements)
Returns a Collection of all the permutations of the specified Collection.




回答2:


There's the PermutationIterator class 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).

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."



来源:https://stackoverflow.com/questions/12013584/permutations-combinatorics-library-for-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!