• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

questions

 
kevin goon
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thank you so much!!
 
sandip karmarkar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Axel Janssen
Ranch Hand
Posts: 2166
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Scott Appleton
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic