-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
23 lines (17 loc) · 737 Bytes
/
Test.java
File metadata and controls
23 lines (17 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.tcs;
public class Test {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello"); // creates a new object in stack
System.out.println(s1 == s2); //== and .equal() both are meant for
System.out.println(s1 == s3); //reference comparison in Object class.
System.out.println(s1.equals(s2)); // But String class override the .equal() for
System.out.println(s1.equals(s3)); // content comparison and Hence True for same content.
String e = new String("JavaScript");
String f = new String("JavaScript");
if(e!=f) {
System.out.println("Two String has same content but pointing to different object");
}
}
}