#Help with strings
17 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @true steeple! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
The main difference is that == is used for reference comparison
But .equals is used for content operation
Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.
So like it checks if the address of both the strings is same?
Yes
You can test it by doing this trick
String s1 = "HELLO";
String s2 = "HELLO";
String s3 = new String("HELLO");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3));
s3 and s1 content is same when we use .equal it will return true
But s3 have new string object with new memory of string HELLO so when you do s1 == s3 it will return false
so like what exactly does an address mean?
Address means the memory which the operating system assigned to store the variable
When we use new keyword it creates new memory for it
Oh okay, thank you so much!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.