FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-basics/core-java/strings/CompareStrings.java at master · CodeForHunger/java-basics · GitHub
CodeForHunger
/
java-basics
Public
forked from
learning-zone/java-basics
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-basics
/
core-java
/
strings
/
CompareStrings.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (31 loc) · 1 KB
Breadcrumbs
java-basics
/
core-java
/
strings
/
CompareStrings.java
Copy path
File metadata and controls
38 lines (31 loc) · 1 KB
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
33
34
35
36
37
38
package
strings
;
public
class
CompareStrings
{
public
static
void
main
(
String
[]
args
) {
String
s1
=
"Ram"
;
String
s2
=
"Ram"
;
String
s3
=
new
String
(
"Ram"
);
String
s4
=
new
String
(
"Ram"
);
String
s5
=
"Shyam"
;
String
s6
=
null
;
String
s7
=
null
;
try
{
System
.
out
.
println
(
"
\n
Comparing String with equals(): "
);
System
.
out
.
println
(
s1
.
equals
(
s2
));
System
.
out
.
println
(
s1
.
equals
(
s3
));
System
.
out
.
println
(
s3
.
equals
(
s4
));
//System.out.println(s6.equals(s7)); // NullPointerException
System
.
out
.
println
(
"
\n
Comparing String with ==:"
);
System
.
out
.
println
(
s1
==
s2
);
System
.
out
.
println
(
s1
==
s3
);
System
.
out
.
println
(
s1
==
s4
);
System
.
out
.
println
(
s6
==
s7
);
System
.
out
.
println
(
"
\n
Comparing String with compareTo():"
);
System
.
out
.
println
(
s1
.
compareTo
(
s3
));
System
.
out
.
println
(
s1
.
compareTo
(
s5
));
//System.out.println(s6.compareTo(s7)); // NullPointerException
}
catch
(
Exception
e
) {
System
.
out
.
println
(
"Exception: "
+
e
);
e
.
printStackTrace
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL