SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
Originally posted by Mohammad Khan:
No reply so far ! ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
instances of StringBuffer and StringBuilder could be considered "works in progress." These are Strings in the making -- not a final product.
Originally posted by Paul Yule:
... You can always get the "value" of the String buffer with a toString and equals on that.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
[QB]
Wow, after 12 full minutes? With gaps like that, one might get the impression this is a forum (where patience is a virtue) rather than a real-time chat room.
I apologize !!
Paul Yule wrote:
Originally posted by marc weber:
instances of StringBuffer and StringBuilder could be considered "works in progress." These are Strings in the making -- not a final product.
I agree. Besides, more explicitly, You can always get the "value" of the String buffer with a toString and equals on that.
marc weber wrote:instances of StringBuffer and StringBuilder could be considered "works in progress." It doesn't make much sense to compare things while they're still being assembled
seetharaman venkatasamy wrote:
marc weber wrote:instances of StringBuffer and StringBuilder could be considered "works in progress." It doesn't make much sense to compare things while they're still being assembled
Excellent
akash kumar wrote:Hi seetharaman! I don't understand how instances of StringBuffer and StringBuilder could be considered "works in progress" whole through its life time.
seetharaman venkatasamy wrote:
Concatenate the objects in String is worst instead use StringBuffer
String str = "akash " + "kumar" //which will create 3 objects
seetharaman venkatasamy wrote:
akash kumar wrote:Hi seetharaman! I don't understand how instances of StringBuffer and StringBuilder could be considered "works in progress" whole through its life time.
StringBuilder is Designed to ba a Mutable Object to avoid Creation of unnecessary Objects.
Example :
Concatenate the objects in String is worst instead use StringBuffer
String str = "akash " + "kumar" //which will create 3 objects
where as StringBuilder sb = new StringBuilder("akash"); sb.append("kumar");//which will create 1 object
akash kumar wrote:
What my understanding is Strings are immutable objects meant for storing strings, not ideal for manipulations as it would require creating, copying, and destroying lot of intermediate String objects. StringBuffer and StringBuilder are ideal for manipulations as they are mutable objects and hence can be used for manipulating and storing the strings.
Henry wrote:
String str = akashvar + kumarvar;
it will be compiled to this...
String str = new StringBuilder().append(akashvar).append(kumarvar).toString();
KrishnaPrasad raghavan wrote:
Hence sb1.equals(sb2) will never be the same as it is pointing to two different references.
KrishnaPrasad raghavan wrote:Hi,
sb1.toString().equals(sb2.toString()) would make sense as it is comparing the value.
Akash Kumar wrote :
"The equals() method is meant to be used for comparing the values(or logically equivalent instances) and not the reference. ".
We can walk to school together. And we can both read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|