Here is an example, as you asked :
// myArray with 1,2,3,...,n values
int[] myArray = new int[] {1, 2, 3};
// Convert it in a List to use it through guava Collections
List<Integer> vals = Ints.asList(myArray);
// Compute all permutations using Guava Collections API
Collection<List<Integer>> orderPerm = Collections2.orderedPermutations(vals);
// Convert the result in List of Lists to get indexed values by number (to display them, easier to access than using an Iterator)
List<List<Integer>> myTwoDimensionalArray = new ArrayList<>(orderPerm);
// Loop over the result to display the 2 dimensional array
for (int dim1 = 0 ; dim1 < myTwoDimensionalArray.size() ; dim1++) {
String dim2 = "";
// Here I build a string to display the numbers without the brackets (not necessary)
for (int i = 0 ; i < myTwoDimensionalArray.get(dim1).size() ; i++) {
if (i > 0) {
dim2 += ",";
}
dim2 += myTwoDimensionalArray.get(dim1).get(i);
}
// Displaying the 2 dimensional results
System.out.println(dim1 + " : " + dim2);
// Uncomment here to display with brackets directly
// System.out.println(dim1 + " : " + myTwoDimensionalArray.get(dim1));
}
Just to be clear, here are the imports :
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.google.common.collect.Collections2;
import com.google.common.primitives.Ints;
It displays this output :
0 : 1,2,3
1 : 1,3,2
2 : 2,1,3
3 : 2,3,1
4 : 3,1,2
5 : 3,2,1
This one with brackets :
0 : [1, 2, 3]
1 : [1, 3, 2]
2 : [2, 1, 3]
3 : [2, 3, 1]
4 : [3, 1, 2]
5 : [3, 2, 1]
I've imported 2 jars in my project (using Maven) to use Guava collections :
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
If you don't know how to use Maven, just download these jars from the maven repository and copy them in your workspace to add them in your Java classpath.
If your don't work in a workspace (like Eclipse), just compile your class using the javac -classpath option to add these jars in the compilation.
Here is a documentation about javac compilation : https://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/tooldocs/solaris/javac.html
Collections2.permutations(vals)does exactly what you want.for (List<Integer> val : orderPerm)line in your code seems to be exactly the example that you asked for. It goes through all permutations, one at a time. If you want something else, then please be more specific in your question.