Regards
SaurabhSri (SCJP 1.5)
Java hobbyist.
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by Sagar Rohankar:
The string literals are never matched with == operator , there are two methods for this
String#equals()
String#eqaulsIgnorecase() [see doc]
When you check string equality thru this == op , this simply checks for bit pattern , not the contents !!
Hope this clarifies the things .
Java hobbyist.
Thanks & Regards
Sidharth Pallai
Originally posted by Sidharth Pallai:
Hi Sagar,
Is it advised not to compare String literals with = =.
Any if below code gives true
Then what is wrong with issue posted by Darshan?
Can you be bit precise regarding your suggestion.
Java hobbyist.
Originally posted by Ronald Schild:
This prints "false", while the string content is true, for example, because a and b refer to explicitly allocated different objects.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Thanks & Regards
Sidharth Pallai
Originally posted by darshan karle:
hi all,
as per my knowledge if two string literal have same value then there is only one object exist. why two objects exist here.....???
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by Sidharth Pallai:
Though == comparision is not a real world approach,but i wish to know the consequences of it when compared to the way the post is concerned about.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Thanks & Regards
Sidharth Pallai
Originally posted by Sidharth Pallai:
"Methods like trim() and toLowerCase() always return new string objects to use;
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by darshan karle:
raghav please not no object is created at compile time and i think i got answer for the question.and i agree with ronald.
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Originally posted by Raghavan Muthu:
That's because of the explicit invocation of 'new' in both the statements.
Java hobbyist.
After line 2 has executed, a string object with the content "Hello" is eligible for garbage collection.
One string object with the content "Hello World!" is eligible for garbage collection.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Only after execution of line 4.. , a referenced sting is returned to String pool and String object (created with "new" ) b, is eligible for GC..
Java hobbyist.
Java hobbyist.
hi all,
i got this question from the site:http://www.angelfire.com/or/abhilash/Main.html. i am pasting the question below
if(" String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Strings computed by concatenation at run time are newly created and therefore distinct.
Java hobbyist.
SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
a wee bit from the empire
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|