英文:
(Java) Creating permutations of an array-list using for loops
问题
我已经查阅了大量的讨论串,但始终未能找到我正在寻找的解决方案。
我有一个数组列表,希望创建一个for循环,用于生成它的排列(abc、cba、acb等),并将它们分别存储在一个数组列表或字符串数组中。我所看到的几乎每个解决方案都涉及创建一个公共类。但我需要这个循环专属于一个公共类内部运行。
英文:
I have looked through a ton of threads and haven't been able to find the solution that I'm looking for.
I have an arraylist and I want to make a for loop that will generate its permutations (abc, cba, acb, etc) and store them individually in an arraylist or string array. Almost every solution I have seen involves creating a public class. But I need this loop to work exclusively inside of a public class.
答案1
得分: 1
你不需要自己实现这个(*),你可以直接使用Guava库中的Collections2.permutations(list)方法。
(*)除非你是为了完成一个作业而这样做,否则让他人为你完成实际上只会让你自己受损。
英文:
You don't need to implement this yourself (*), you can just use Collections2.permutations(list), from Guava (an excellent library).
(*) unless you are doing this for an assignment, in which case you're really only shooting yourself in the foot by letting others do it for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论