Find All permutation of String using Iteration How to find all permutation of a String in Iterative way ? 

Code (Recursion) :

private void permute(String str, int l, int r)
{
    if (l == r)
        System.out.println(str);
    else
    {
        for (int i = l; i &lt;= r; i++)
        {
            str = swap(str,l,i);
            permute(str, l+1, r);
            str = swap(str,l,i);
        }
    }
}


public String swap(String a, int i, int j)
{
    char temp;
    char[] charArray = a.toCharArray();
    temp = charArray[i] ;
    charArray[i] = charArray[j];
    charArray[j] = temp;
    return String.valueOf(charArray);
}
Wikipedia describes several algorithms, including:


Heap's algorithm.
Steinhaus–Johnson–Trotter algorithm.