Results 1 to 2 of 2
Thread: Search for object by keyword
- 03-23-2012, 08:58 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
Search for object by keyword
Hi,
I have an ArrayList of objects type Contact. Every Contact contains first name, last name, phone number and e-mail (all of them String).
I have to write a method which search for a keyword in the records and return true if this keyword has been found anywhere in it. The method I came up with is:
public boolean match(Object otherObject)
{
if (otherObject ==null)
{
return false;
}
else if (getClass() != otherObject.getClass())
{
return false;
}
else
{
Contact otherContact = (Contact)otherObject;
return (first.equals(otherContact.first) ||
last.equals(otherContact.last)||
phone.equals(otherContact.phone)||
email.equals(otherContact.email));
}
}
and it works fine. The problem is that in this case it returns true only if the two values are exactly the same. I need to modify it in a way that even if the keyword is "ohn" records with name "John" to return true. It has to work with any keyword and to search for it in all object variables. Thanks
- 03-23-2012, 09:08 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Any advice - java search algorithms which accept multiple search parameters
By Alfster in forum New To JavaReplies: 4Last Post: 03-24-2011, 11:50 PM -
Not able to highlight the search key work in wild card search
By annappa in forum LuceneReplies: 0Last Post: 10-29-2009, 09:28 AM -
make search function ike eclipse search in window->preference
By i4ba1 in forum Advanced JavaReplies: 5Last Post: 08-26-2008, 03:43 PM -
Search a object in a vector
By TalhaS in forum New To JavaReplies: 2Last Post: 04-30-2008, 02:05 PM -
how to search xml file data based on the given keyword from html form?
By nicemothi in forum XMLReplies: 0Last Post: 04-04-2008, 09:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks