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 6581205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:07:24+00:00 2026-05-25T16:07:24+00:00

I have a simple application that reads data in small strings from large text

  • 0

I have a simple application that reads data in small strings from large text files and saves them to a database. To actually save each such String, the application calls the following method several (may thousands, or more) times:

setValue(String value)
{
    if (!ignore(value))
    {
         // Save the value in the database
    }
}

Currently, I implement the ignore() method by just successively comparing a set of Strings, e.g.

public boolean ignore(String value)
{
    if (value.equalsIgnoreCase("Value 1") || (value.equalsIgnoreCase("Value 2"))
    {
        return true;
    }

    return false;
}

However, because I need to check against many such “ignorable” values, which will be defined in another part of the code, I need to use a data structure for this check, instead of multiple consecutive if statements.

So, my question is, what would be the fastest data structure from standard Java to to implement this? A HashMap? A Set? Something else?

Initialization time is not an issue, since it will happen statically and once per application invocation.

EDIT: The solutions suggested thus far (including HashSet) appear slower than just using a String[] with all the ignored words and just running “equalsIgnoreCase” against each of these.

  • 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-25T16:07:25+00:00Added an answer on May 25, 2026 at 4:07 pm

    Use a HashSet, storing the values in lowercase, and its contains() method, which has better lookup performance than TreeSet (constant-time versus log-time for contains).

    Set<String> ignored = new HashSet<String>();
    ignored.add("value 1"); // store in lowercase
    ignored.add("value 2"); // store in lowercase
    
    public boolean ignore(String value) {
        return ignored.contains(value.toLowerCase());    
    }
    

    Storing the values in lowercase and searching for the lowercased input avoids the hassle of dealing with case during comparison, so you get the full speed of the HashSet implementation and zero collection-related code to write (eg Collator, Comparator etc).

    EDITED
    Thanks to Jon Skeet for pointing out that certain Turkish characters behave oddly when calling toLowerCase(), but if you’re not intending on supporting Turkish input (or perhaps other languages with non-standard case issues) then this approach will work well for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a small application that reads data from a database and displys it
I have an small ASP.NET application that reads data from a table and sends
I have a simple Android native java application that reads data from a Bluetooth
I have a silverlight 3 application, that fetches some simple data from a ms-sql-server
I have a PyQt application that reads and writes data files. I am including
Currently i have an application that reads and writes several properties from one or
I have a rather strange problem. I have a very simple application that reads
I have an application that streams through 250 MB of data, applying a simple
I have a simple application that loads an unmanaged dll and passes a few
I have a simple c++ application that generates reports on the back end of

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.