Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Hey i have a very silly doubt...... String s="abc"; String s1=new String("abc"); if (s1.equals(s)) System.out.println("true") else System.out.println("false") also String s ="abc"; s=s+"def"; System.out.println(s); What will the value of s be now??? Help someone
The answer to first question will be "true".The string class overrides the equals method it inherites from 'Object' class so equals in String provides a deep comparison which is a chracter by character comparison(unlike== which is shallow comparison). The value of string s will will be "abcdef" in your 2nd question.The + operator is overloaded by the Java Language which allows string concatenation to be done in this manner.
<PRE>String s ="abc"; s=s+"def"; System.out.println(s); What will the value of s be now??? </PRE> What happens here is that s now denotes a different String object ("abcdef") from the one it denoted before ("abc"). s is not a String but a String object reference.
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
hi, String s ="abc"; s=s+"def"; System.out.println(s); What will the value of s be now??? instead of saying s=s+"def"; if u said String s ="abc"; s+"def"; System.out.println(s); then the value of s still remains "abc". This is because the new string formed is not assigned to any reference of type string and is hence "lost" to be garbage collected. Rahul.
[This message has been edited by rahul_mkar (edited June 08, 2000).]
All of the following truths are shameless lies. But what about this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss