Posts

Showing posts from 2015

Handling Custom Object With Java Collections

Image
Hi all, This post is mainly to explain the need of hashcode() and equals() function in java. Why thus all the Wrapper classes have hashcode() and equals() method implementation and they are known as good key for Hashmap?Let me explain it here with custom object example because in all the wrapper class you will be having hashcode() and equals() method implementation by default I am going to have Employee object as a key in Hashmap,when you create your own custom object as a key for Hashmap we need override both hashcode() and equals()  method . This is used to maintain unique property in Hashmap key . Employee class with hashcode and equals method implementation /**  *  * @author Saradha M  * @since 1.0  */ public class Employee { private int empId; private String name; /** * @param empId * @param name * @author Saradha M * @since 1.0 */ public Employee(int empId, String name) { super(); this.empId = empId; this...