
Hi,
can any one please share the code to check the
String s1="abcd"; String s2="bacd";
is permutaion of each other??

Here is an example that prompts the user to enter two strings in order to check whether they are permutation of each other or not.
class CheckPermutation{
public static boolean isPermutation(String st1, String st2) {
if (st1.length() != st2.length()) {
return false;
}
int[] count = new int[256];
for (int i = 0; i < st1.length(); ++i) {
++count[st1.charAt(i)];
}
for (int i = 0; i < st2.length(); ++i) {
if (--count[st2.charAt(i)] < 0) {
return false;
}
}
return true;
}
public static void main(String[] args)
{
String st1="abcd";
String st2="bacd";
if(isPermutation(st1,st2)){
System.out.println("Strings are permutations of each other.");
}
else{
System.out.println("Strings are not permutations of each other.");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.