-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExercise.java
More file actions
27 lines (21 loc) · 942 Bytes
/
StringExercise.java
File metadata and controls
27 lines (21 loc) · 942 Bytes
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
public class StringExercise{
public static void main(String[] args) {
// int a = 10; // primitive, stores in stack
// int b[] = {1,2,3,4,5}; // primitive, b in stack & values in heap.
String a = "iamjayandhan";
String b = "iamjayandhan";
//String comparisons
//1. == (checks ref var)
// System.out.println(a == b); //true (both ref vars points to same obj)
//create diff objs of same value?
String c = new String("JD");
String d = new String("JD");
//both works because this creates obj outside the string pool
// System.out.println(c == d); //false (both obj are diff, though they has same val)
// .equals() (checks only value)
System.out.println(a==b); //true
System.out.println(a.equals(b)); //true
System.out.println(c==d); //false
System.out.println(c.equals(d)); //false
}
}