-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Types_String.java
More file actions
48 lines (23 loc) · 950 Bytes
/
String_Types_String.java
File metadata and controls
48 lines (23 loc) · 950 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.mywork;
public class String_Types_String {
public static void main(String[] args) {//String
String s = "Java";
System.out.println(System.identityHashCode(s));//885284298
//identify the memory location stored
//string duplicate
String a = "Java";
System.out.println(System.identityHashCode(a));//885284298
//if we duplicate the string memory will be shared
//-----------------------------------------------
//string concat
String concat = a.concat("program");
System.out.println(concat);//javaprogram
//it will merge the two strings
System.out.println(System.identityHashCode(concat));//1389133897
//if we concat the string new memory will be created
System.out.println(s);//java
//if we call the object the string value cannot be changed
System.out.println(a);//Java
//if we call the object the string value cannot be changed
}
}