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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:45+00:00 2026-05-31T22:04:45+00:00

I want to implement a case insensitive hash map. This question by itself isn’t

  • 0

I want to implement a case insensitive hash map. This question by itself isn’t new, but I wanted to add extra functionality and don’t know what general direction to take. I want the client to be able to do something like this:

boolean preserve_case = true;
Map<String, MyClass> maplet = new CaseInsensitiveHashMap<MyClass>(preserve_case); // If the client enters true at construction, then the put, get, and remove methods should still be case insensitive, but the entry and key sets should preserve the case that the client used when calling put.

maplet.put("FoO", my_class);

MyClass bar = maplet.get("foo"); // Should return a reference to my_class

Set<Entry<String, MyClass>> case_sensitive_set = maplet.entrySet(); // Since the client input true to preserve order, this entry set should be ["FoO"=my_class.toString()]

I can handle most of this pretty well; I simply keep a HashMap on the backend. When a client puts anything in, I uppercase the key before adding it to the map.

I’m just having a hard time writing the keySet() and entrySet() methods. I want the returned entry set and key set to be backed by the map, as is the standard with Java maps.

However, the only way I can think of handling this is to create a second backing data structure, something like a preserved_case_map, which contains the input.toUpperCase() => input as key value pairs. When the client calls for the entrySet() (or keySet()), I can construct the returned entry set by looping through the preserved_case_map. The problem here is that the returned entry set will not be modified if I make changes to the HashMap, unless I’m misunderstanding something…

Let me know if this makes sense, or if I’m convoluting a simple situation.

  • 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-31T22:04:46+00:00Added an answer on May 31, 2026 at 10:04 pm

    You could use a TreeMap with case insensitive comparator. The TreeMap will use the comparator to compare keys in a case-insensitive way:

        Map<String, Integer> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    
        map.put("Foo", 1);
        map.put("fOo", 2);
    
        System.out.println(map.get("foo")); // prints 2
        System.out.println(map.keySet()); // prints [Foo]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a collection (a bit like a map but for single
I want implement in my software solution an VBA editor but in c# 3.0.
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement a chat application but I don't want to use timeout
I want to implement deletecomment function in my website but I don't want my
I want to implement a workflow system on a new website which i am
I want to implement this function: Public Function GetFunc(Of TSource, TResult) _ selector As
Probably this question was already asked before, but my google-fu and SO-Search did not
I want to implement a simple SVM classifier, in the case of high-dimensional binary
if i want to implement am http server. i create new actor per request.

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.