We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f1df0c commit c9e6fbdCopy full SHA for c9e6fbd
Check this string is anagram or not
@@ -0,0 +1,35 @@
1
+import java.util.Arrays;
2
+
3
+class Main {
4
+ public static void main(String[] args) {
5
+ String str1 = "java";
6
+ String str2 = "vaaj";
7
8
9
+ if(str1.length() == str2.length()) {
10
11
12
+ char[] charArray1 = str1.toCharArray();
13
+ char[] charArray2 = str2.toCharArray();
14
15
16
+ Arrays.sort(charArray1);
17
+ Arrays.sort(charArray2);
18
19
20
+ boolean result = Arrays.equals(charArray1, charArray2);
21
22
+ if(result) {
23
+ System.out.println(str1 + " and " + str2 + " are anagram.");
24
+ }
25
+ else {
26
+ System.out.println(str1 + " and " + str2 + " are not anagram.");
27
28
29
30
31
32
33
+}
34
35
0 commit comments