FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/strings/CheckAnagrams.java at master · loisoft/Java · GitHub
loisoft
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
strings
/
CheckAnagrams.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (29 loc) · 902 Bytes
Breadcrumbs
Java
/
strings
/
CheckAnagrams.java
Copy path
File metadata and controls
32 lines (29 loc) · 902 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
29
30
31
32
package
strings
;
import
java
.
util
.
Arrays
;
/**
* Two strings are anagrams if they are made of the same letters arranged differently (ignoring the
* case).
*/
public
class
CheckAnagrams
{
public
static
void
main
(
String
[]
args
) {
assert
isAnagrams
(
"Silent"
,
"Listen"
);
assert
isAnagrams
(
"This is a string"
,
"Is this a string"
);
assert
!
isAnagrams
(
"There"
,
"Their"
);
}
/**
* Check if two strings are anagrams or not
*
* @param s1 the first string
* @param s2 the second string
* @return {@code true} if two string are anagrams, otherwise {@code false}
*/
public
static
boolean
isAnagrams
(
String
s1
,
String
s2
) {
s1
=
s1
.
toLowerCase
();
s2
=
s2
.
toLowerCase
();
char
[]
values1
=
s1
.
toCharArray
();
char
[]
values2
=
s2
.
toCharArray
();
Arrays
.
sort
(
values1
);
Arrays
.
sort
(
values2
);
return
new
String
(
values1
).
equals
(
new
String
(
values2
));
}
}
Back
|
FazBrowse Home
|
New Git URL