- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathCheckPermutation.java
28 lines (24 loc) · 850 Bytes
/
CheckPermutation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//For a given two strings, 'str1' and 'str2', check whether they are a permutation of each other or not.
packageString;
importjava.util.*;
publicclassCheckPermutation {
publicstaticbooleancheckPermutation(Stringstr1 , Stringstr2) {
//To covert into character array.
char [] c1= str1.toCharArray();
char [] c2= str2.toCharArray();
//Sort thr array.
Arrays.sort(c1);
Arrays.sort(c2);
//return the value into string.
str1=newString(c1);
str2=newString(c2);
//check wheter they are equal or not.
returnstr1.equals(str2);
}
publicstaticvoidmain(String[] args) {
Stringstr1 = "abc";
Stringstr2 ="acb";
booleani = checkPermutation(str1, str2);
System.out.println(i);
}
}