Swapping every letter with every other letter in a string
to swap every letter with every other letter in a string


In other words you need all permutations of a string. Ok not all: no need in null set.  


  I would just like to make it efficient as possible. 


Just wanted to show you another solution. A crazy one with a recursion:
https://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string

public static void permutation(String str) { 
    permutation("", str); 
}

private static void permutation(String prefix, String str) {
    int n = str.length();
    if (n == 0) System.out.println(prefix);
    else {
        for (int i = 0; i &lt; n; i++)
            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
}


Quick solution to get it in one line with commas: 

public static String permutation(String str) {
        String res = permutation("", str);
        return res.substring(0, res.length()-2);
    }

private static String permutation(String prefix, String str) {
    String res = "";
    int n = str.length();
    if (n == 0) res = res + prefix + ", ";
    else {
         for (int i = 0; i &lt; n; i++)
             res = res + permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
    return res;
 }


Output:
rya, ray, yra, yar, ary, ayr

Less code, but definitely not the most efficient: calling charAt and substring a lot of time - not a good way.  

In that link there are alot of other examples how to do it.