Created
August 22, 2015 07:41
-
-
Save reza-ryte-club/e7d30fa84d0a449f1a7d to your computer and use it in GitHub Desktop.
Check whether a string is a permutation of another string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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