forked from amitsrivastava4all/JavaBatch1130June
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringExample.java
35 lines (34 loc) · 919 Bytes
/
StringExample.java
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
class StringExample{
public static void main(String args[]){
String a = "Hello User".intern(); // String Literal Way (1 or 0 Object)
String c = "Hello User".intern();
Runtime r = Runtime.getRuntime();
System.out.println("Tot Mem "+r.totalMemory());
System.out.println("Free Mem "+r.freeMemory());
System.out.println("Used Mem "+(r.totalMemory()-r.freeMemory()));
for(int i = 1; i<=100000; i++){
String x = "Hello";
}
System.out.println("Tot Mem "+r.totalMemory());
System.out.println("Free Mem "+r.freeMemory());
System.out.println("Used Mem "+(r.totalMemory()-r.freeMemory()));
if(a==c)
{
System.out.println("Same Ref ");
}
else
{
System.out.println("Not Same Ref ");
}
String b = new String("Hello User").intern(); // new object way 2 or 1 Objects
if(a==b){
System.out.println("Same Ref of a and b ");
}
else
{
System.out.println("Not Same Ref of a and b ");
}
//System.out.println("Main Call ");
//main(null);
}
}