[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Searching for a substring in a Map

Posted on 2003-11-10
5
Medium Priority
?
207 Views
Last Modified: 2010-03-31
I have a list of 3000 items.
Each item has key and value.

I need to find all the occurrence in the list whose value matches a substring.

Example:
My input is "home" and my list is:

Key              Value
001              home gardening
002              stay at home
003              office supplies
004              working from home - guide
005              the homeland office

The output should return the following items:
001, 002, 004 and 005.

I can use a vector and using a loop, perform a string.indexOf validation for each item in the list. Is there a more efficient way of doing this.
0
Comment
Question by:bennies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9714551
>>Is there a more efficient way of doing this.

No - in a word.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 9714586
...unless of course you can mark the items in some way on insertion, and then maintain a separate index.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9715772
I'd go along with CEHJs comments here.

There are always *different* ways of doing things, but that all depends on what you mean by efficiency.  Remember, efficiency is always a trade-off between space and speed.

The way you're doing it at the moment is probably about the best you could do in terms of space, implementing a separate index might make the code faster, but increases the space it takes.

It all depends on which (space or speed) you want to sacrifice ;-)

(Note.  Sometimes it is possible to create a solution that is more efficient in both space and speed.  This usually leads to unreadable/unmaintainable code ;-))
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question