Re: [algogeeks] Java Collections
you need to override equals and hashcode methods. On Mon, Dec 5, 2011 at 12:23 PM, pa7751 pa7...@gmail.com wrote: Hi I have a Person Object that has members: firstname, lastname and DOB public class Person { private String firstName; private String lastName; private Date dob; /** Construct a Person given the first name, last name, and birth date. */ public Person(String firstName, String lastName, Date dob) { if (firstName == null || lastName == null || dob == null) { throw new IllegalArgumentException(); } this.firstName = firstName; this.lastName = lastName; this.dob = dob; } } The application uses Person objects in Collections, placing them into Collection implementations and querying if a Person is in a Collection using the Collection.contains() method. The application also uses Person objects as keys in Maps to associate other objects with Persons and to efficiently look up those objects based on Person. How can I modify this Person Object so that the lookup is efficient? Any help?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Java Collections
Hi I have a Person Object that has members: firstname, lastname and DOB public class Person { private String firstName; private String lastName; private Date dob; /** Construct a Person given the first name, last name, and birth date. */ public Person(String firstName, String lastName, Date dob) { if (firstName == null || lastName == null || dob == null) { throw new IllegalArgumentException(); } this.firstName = firstName; this.lastName = lastName; this.dob = dob; } } The application uses Person objects in Collections, placing them into Collection implementations and querying if a Person is in a Collection using the Collection.contains() method. The application also uses Person objects as keys in Maps to associate other objects with Persons and to efficiently look up those objects based on Person. How can I modify this Person Object so that the lookup is efficient? Any help?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Java Collections
Hi I have a Person Object that has members: firstname, lastname and DOB public class Person { private String firstName; private String lastName; private Date dob; /** Construct a Person given the first name, last name, and birth date. */ public Person(String firstName, String lastName, Date dob) { if (firstName == null || lastName == null || dob == null) { throw new IllegalArgumentException(); } this.firstName = firstName; this.lastName = lastName; this.dob = dob; } } The application uses Person objects in Collections, placing them into Collection implementations and querying if a Person is in a Collection using the Collection.contains() method. The application also uses Person objects as keys in Maps to associate other objects with Persons and to efficiently look up those objects based on Person. How can I modify this Person Object so that the lookup is efficient? Any help?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.