Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4244070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:39:36+00:00 2026-05-21T03:39:36+00:00

Hi I am populating a Hashmap with a dictionary.txt file and I am splitting

  • 0

Hi I am populating a Hashmap with a dictionary.txt file and I am splitting the hashmap into sets of word lengths.

Im having trouble searching the Hashmap for a pattern of “a*d**k”;

Can anyone help me?

I need to know how to search a Hashmap?

I would really appreciate if you could help me.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:39:37+00:00Added an answer on May 21, 2026 at 3:39 am

    A HashMap is simply the wrong data structure for a pattern search.

    You should look into technologies that feature pattern searching out of the box, like Lucene


    And in answer to this comment:

    Im using it for Android, and its the
    fastest way of searching
    .

    HashMaps are awfully fast, that’s true, but only if you use them as intended. In your scenario, hash codes are not important, as you know that all keys are numeric and you probably won’t have any word that’s longer than, say, 30 letters.

    So why not just use an Array or ArrayList of Sets instead of a HashMap and replace map.get(string.length()) with list.get(string.length()-1) or array[string.length()-1]. I bet the performance will be better than with a HashMap (but we won’t be able to tell the difference unless you have a reaaaallly old machine or gazillions of entries).

    I’m not saying my design with a List or Array is nicer, but you are using a data structure for a purpose it wasn’t intended for.


    Seriously: How about writing all your words to a flat file (one word per line, sorted by word length and then by alphabetically) and just running the regex query on that file? Stream the file and search the individual lines if it’s too large, or read it as a String and keep that in memory if IO is too slow.


    Or how about just using a TreeSet with a custom Comparator?

    Sample code:

    public class PatternSearch{
    
        enum StringComparator implements Comparator<String>{
            LENGTH_THEN_ALPHA{
    
                @Override
                public int compare(final String first, final String second){
    
                    // compare lengths
                    int result =
                        Integer.valueOf(first.length()).compareTo(
                            Integer.valueOf(second.length()));
                    // and if they are the same, compare contents
                    if(result == 0){
                        result = first.compareTo(second);
                    }
    
                    return result;
                }
            }
        }
    
        private final SortedSet<String> data =
            new TreeSet<String>(StringComparator.LENGTH_THEN_ALPHA);
    
        public boolean addWord(final String word){
            return data.add(word.toLowerCase());
        }
    
        public Set<String> findByPattern(final String patternString){
            final Pattern pattern =
                Pattern.compile(patternString.toLowerCase().replace('*', '.'));
            final Set<String> results = new TreeSet<String>();
            for(final String word : data.subSet(
                // this should probably be optimized :-)
                patternString.replaceAll(".", "a"),
                patternString.replaceAll(".", "z"))){
                if(pattern.matcher(word).matches()){
                    results.add(word);
                }
            }
            return results;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When populating the queue from the contents of the file, depth does not seem
I am having issues populating a dropdown list with a JSON List. Here is
I am currently populating an NSTableView through the controller (MVC design pattern) where I
I have code I am working on, but I am having issues populating the
Hi i have a problem populating hashmap with a loop, i need to store
I'm populating an anonymous object from an XML file. Up until now, commentary.Elements(Commentator) has
Im populating a ListView using the following: list = (ListView) findViewById(R.id.historylist); ArrayList<HashMap<String, String>> mylist
Hi i am populating data into excel worksheet using DDE.Execute command from Oracle forms.
Im populating a GridView from List so am forced to use TemplateField controls to
Im populating viewdata with a bunch of css style properties. <span style=font-size:50pt; font-family:<%= ViewData[font]%>;><%=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.