Given a string str, the task is to print all the permutations of str.
A permutation is an arrangement of all or part of a set of objects, with regard to the order of the arrangement.
For instance, the words ‘bat’ and ‘tab’ represents two distinct permutation (or arrangements) of a similar three letter word.
Input: str = “abc”
Output: abc acb bac bca cba cab
Input: str = “bat”
Output: bat bta abt atb tba tab
Approach: Write a recursive function that will generate all the permutations of the string. Terminating condition will be when the passed string is empty, in that case the function will return an empty ArrayList.
Below is the implementation of the above approach:
abc bac bca acb cab cba
- Print all subsequences of a string using ArrayList
- Convert an ArrayList of String to a String array in Java
- Minimum length of string having all permutation of given string.
- Java ArrayList to print all possible words from phone digits
- Lexicographically n-th permutation of a string
- String which when repeated exactly K times gives a permutation of S
- Number of distinct permutation a String can have
- Find n-th lexicographically permutation of a string | Set 2
- Lexicographically smallest permutation of a string with given subsequences
- Maximum even length sub-string that is permutation of a palindrome
- Print shortest path to print a string on screen
- Print all possible ways to convert one string into another string | Edit-Distance
- Print the longest prefix of the given string which is also the suffix of the same string
- Permutation of a string with maximum number of characters greater than its adjacent characters
- ArrayList of ArrayList in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.