(Java)使用for循环创建数组列表的排列

huangapple go评论70阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年9月1日 02:49:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63676528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定