+ 4

Why String str="hello" and String str = new String("hello") are different?

when we compare both by comparison operator it will give false as result

28th Sep 2018, 6:06 PM
Kuldeep Verma
Kuldeep Verma - avatar
4 Answers
+ 8
Looks like Java. basically new string just creates a new value on a heap. comparison checks for reference equality, so it will return false for that code. Actually even if you don't use new to allocate a memory it still might do it by itself (depending on some things)
28th Sep 2018, 6:10 PM
WittyBit
WittyBit - avatar
0
yes,the new string is the object string while, the other one is normal string js
10th Oct 2018, 5:56 PM
Jackson Mihayo
Jackson Mihayo - avatar
- 2
hello is a string which assign to str and string str= new str("hello") is assing to constracture value
1st Oct 2018, 2:32 PM
Vishal Suryawanshi
Vishal Suryawanshi - avatar
- 3
mujhe seekhni hai c lenguage sir
4th Oct 2018, 3:37 PM
atul kaushik