Troncoso
VIP Member
meant to say, two arrays being used.
anyways, you're going to have to mod it for your own use obviously, but it might be of some use to you.
Code:import java.util.*; public class Permutation { public ArrayList<String> getPerms(String s) { ArrayList<String> list = new ArrayList<String>(); if (s.length() == 1) list.add(s); else { for (int i = 0; i < s.length(); i++) { char x = s.charAt(i); String y = ""; for (int j = 0; j < s.length(); j++) { if (i != j) y += s.charAt(j); } ArrayList<String> results = getPerms(y); for (String sf : results) { list.add(x + sf); } } } return list; } public static void main(String[] ar) { for (String s : new Permutation().getPerms("abcdefg")) { System.out.println(s); } } }
So this is pretty much taking a string of characters and returning every possible order you could put them in?
Not exactly what I'm doing, but I could definitely see that as an approach to my problem.