Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
<apex:page controller="StringPermutations"> <apex:form > <apex:pageBlock > <apex:inputText label="String" value="{!str}"/>/> <apex:commandButton value="Check Permutation values of string" action="{!Permutations}"/> <apex:repeat value="{!PermutationList}" var="p"> <apex:outputText label="Permuted Values" value="{!p}"><br/></apex:outputText> </apex:repeat> </apex:pageBlock> </apex:form> </apex:page>
public class StringPermutations{ public String str{get;set;} Public List<String> PermutationList{get;set;} public void Permutations(){ PermutationList=new List<String>(); permutation1(str); } public void permutation1(String input){ permutation('', input); system.debug('PermutationList'+PermutationList); } public void permutation(String prefix, String str1) { integer n = str1.length(); if (n == 0){ if(prefix!=null){ System.debug(prefix); PermutationList.add(prefix); } } else { for (integer i = 0; i < n; i++) permutation(prefix + str1.substring(i,i+1),str1.substring(0, i) + str1.substring(i+1, n)); } } }
Refer:
https://javarevisited.blogspot.com/2015/08/how-to-find-all-permutations-of-string-java-example.html
Use this java code in apex and make few changes accordingly. Display the output string in vf.
Mark this as best answer if this has solved your query.
Thanks,
Gulafsha
Vf page:
Controller:
Please mark this as best answer if this has helped you.
Regards,
Gulafsha