Skip to content

Instantly share code, notes, and snippets.

@reza-ryte-club
Created August 22, 2015 07:41
Show Gist options
  • Save reza-ryte-club/e7d30fa84d0a449f1a7d to your computer and use it in GitHub Desktop.
Save reza-ryte-club/e7d30fa84d0a449f1a7d to your computer and use it in GitHub Desktop.
Check whether a string is a permutation of another string
import java.util.Arrays;
public class IsPermutation {
public static boolean isPermutation(String str1, String str2){
if(str1.length() != str2.length()) return false;
char[] c1 = str1.toCharArray();
char[] c2 = str2.toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
return Arrays.equals(c1,c2);
}
public static void main(String[] args) {
System.out.println("reverse string");
String word = "Hello world";
String word2 = "Hello wordl";
System.out.println(isPermutation(word,word2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment