using Map to implement efficient searching process - java -


I am creating a Phone Book API in Java. Every name in the phone book is mapped to a set of phone numbers & amp; Address. I want to create a search function which can search for a search parameter name or phone number as an entry in my phone book.

My View All My Entries A: / P>

  Maps & lt; String, phone number & gt; Book = new hashmap & lt; String, phone number & gt; (); Book.put ("name1", new phone number (new integer (12345), new integer (123456); book.get ("name1"); // phononumber is my class which can be different types of phone numbers  

I want to search with both names which are also key and also by value. I can not do this by using hashmap . Is it better to do this The method is to implement an efficient search process?

Map of your phone book Do not use it. It's very limited. Instead create a phonebook class. Create 2 Maps within that class, search for another nickname search for another two-number. Make a pair () regular that adds information to both maps .

  Public class phonebook {Private map & lt; number, by strings, info & gt; private map & lt; string, info & quot; byName;}  

Where is the "information" a category that you have about the person Some states.


Comments