More often than not, you will use a HashSet for storing your duplicate-free collection. For efficiency, objects added to a HashSet need to implement the hashCode() method in a manner that properly distributes the hash codes. While most system classes override the default hashCode() implementation in Object, when creating your own classes to add to a HashSet remember to override hashCode(). As with all the concrete implementations, which implementation you use depends on your specific needs. For inserting, deleting, and locating elements in a Map, the HashMap offers the best alternative. No duplication allowed in HashMap. Hope the above explanation helps u...
What would be a good scenario where a HashMap is more suited than a HashSet or vice versa.
While developing some serious software code, yes, I definitely find HashMap useful in so many places. The purpose of set and map are different, and at some points, u'll definitely need their unique feature. Consider the Properties class, for instance, which is a map implementation. Thats very useful for maintaining a key-value pair of a property name and its value. You can maintain user preferences in a map like this, and use that object through out ur code. I dont think HashSet would be a wise substitute for a scenario like this.
Also, would this type of question be asked at the exam.
Yeah, u can expect some questions along that line, but not exactly the way u ask. [ December 16, 2003: Message edited by: Karthik Veeramani ]
Thanks<br />Karthik<br />SCJP 1.4, CCNA.<br /> <br />"Success is relative. More the success, more the relatives."