Thanks in Advance,
Kousik
apigee, a better way to API!
Originally posted by Vijay Krishna Doddala:
In the example after overriding the methods equals() and hashCode() which two objects become equal, i mean whether objects of Test or StringBuffer are equal, which reduces the size of the HashSet to 4. Pls. explain.
apigee, a better way to API!
all events occur in real time
Originally posted by geethapuni arthanari:
hi kousik,
String objects are maintained in the String Constant Pool.Once the String object is created, it'll maintained in the String Pool.Again the same String Object is not created, it'll be referred from the pool.In this code, you've created the same String Object two times.That second String Object is not newly created, it'll be referred from the pool and HashSet doesn't allow duplicates.So only one String Object is added in the HashSet.
Pls tell me, if i could wrong.
regards,
arthanari.
apigee, a better way to API!
Originally posted by Adam Schaible:
The key here is calling the constructor of String - there's really NO reason to use it, and it is looked at as amateur in the organizations I've worked with.
Originally posted by Adam Schaible:
The difference here is non-compile time constants also exist in the String pool - for example:
public static void main(String[] args) {
String aString = "test";
String bString = "test";
System.out.println(aString == bString);
}
returns true
apigee, a better way to API!
Don't get me started about those stupid light bulbs. |