|
The procedure is for someone else.
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class Test
{
public static void main (String [] args) throws Exception
{
String [] array = new String [] {"1", "2", "3"};
listAll (Arrays.asList (array), "");
}
public static void listAll (List candidate, String prefix)
{
if (prefix.length () == 3)
{
System.out.println (prefix);
}
Ranch
for (int i = 0; i <candidate.size (); i ++)
{
List temp = new LinkedList (candidate);
listAll (temp, prefix + temp.remove (i));
}
}
}
Take 3 digits as an example, set the list of elements to be retrieved to, and to display String as prefix
First traverse to fetch dates from candidate and add to prefix, one less for candidate and one more for prefix
In this way, recursive loops are the best choice. |
|