-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathString3.java
More file actions
36 lines (33 loc) · 1.14 KB
/
Copy pathString3.java
File metadata and controls
36 lines (33 loc) · 1.14 KB
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
package main.java.StringHandling;
/**
* Created by neeraj.bhatnagar on 1/9/2017.
*/
public class String3 {
public static void main(String[] args) {
String s1 = "Neeraj";
String s2 = "Kumar";
String s3 = "Bhatnagar";
String s4 = new String("Neeraj");
String s5 = "Kumar";
/**
* String equals() method compares the original conten of the String.
*/
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
System.out.println(s1.equals(s4));
System.out.println(s2.equals(s5));
/**
* String == operator compares the reference of the String.
*/
String s6 = "Neeraj";
String s7 = "Neeraj";
String s8 = new String("Neeraj");
String s9 = new String ("Neeraj");
System.out.println(s6 == s7); // Will return true as reference is same as both of string are creates using String literal.
System.out.println(s6 == s8);
System.out.println(s7 == s8);
System.out.println(s8 == s9);
System.out.println(s6.equals(s8));
System.out.println(s1 == s6);
}
}