class X public static void main(String args) String a = new String("true"); Boolean b = new Boolean(true); if(a.equals(b)) System.out.println("true"); Compile but prints nothing. Why? Please explain in terms of the equals method. Q2)
������17. Which statement is true for the class java.util.HashSet A. The elements in the collection are ordered B. The collection is guaranteed to be immutable C. The elements in the collection are guaranteed to be unique D. The elements in the collection are accessed using a unique key E. The elements in the collection are guaranteed to be synchronize ans : d ok but c is false? Isnt HashSet kinda like a Set?
Hello Kevin eqauls method is comparing string to Boolean object. The first thing that equals method will check will be the type of object. If String object is getting checked for equals method to Integer or Boolean object it will return false without further check. If String object is getting checked with another String object for equals method, then further checking of content of String will happen. Hope it is useful. Regards Sandip
Hi Kevin, your second question: D. The elements in the collection are accessed using a unique key Isnt HashSet kinda like a Set? Yes, it is. But You access via unique keys in M a p s. In Maps you have key-value pairs and you use a unique key to access the value. HashSets does not have duplicate elements so they are unique, thats right, but you don't a c c e s s this elements with a unique key but with methods of Iterator class.
correct me if i am wrong Axel
[This message has been edited by Axel Janssen (edited June 20, 2001).]
I think Axel is correct. It's not clear in the original post whether d is the answer supplied with the question or whether that's Kevin's answer, but either way I think c instead of d is the correct answer.