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

  • Home
  • SEARCH
  • 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 6595787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:59:06+00:00 2026-05-25T17:59:06+00:00

Is there an implementation of java.util.Map that only allows a value to be read

  • 0

Is there an implementation of java.util.Map that only allows a value to be read once? What I’d like to do is something like this:

Map map = new ReadOnceMap();
map.put("key", "value")
System.out.println(map.get("key")); // prints "value"
System.out.println(map.get("key")); // prints null

EDIT: requirements:

  • existing implementation
  • values are guaranteed to be read at most one time
  • 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-25T17:59:07+00:00Added an answer on May 25, 2026 at 5:59 pm

    Something like this?

    public class GetOnceHashMap<K,V> extends HashMap<K,V> {
        @Override
        public V get(Object key) {
            return remove(key);
        }
    
        @Override
        public Collection<V> values() {
            Collection<V> v = new ArrayList<V>(super.values());
            clear();
            return v;
        }
    
        @Override
        public Set<Map.Entry<K, V>> entrySet() {
            Set<Map.Entry<K, V>> e = new HashSet<Map.Entry<K,V>>(super.entrySet());
            clear();
            return e;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an openID implementation in Java? I would like to use this in
I'm looking for an on-disk implementation of java.util.Map . Nothing too fancy, just something
I have an implementation of java.util.Iterator which requires that the call to next() should
We're getting this error java.lang.NullPointerException at java.util.ArrayList.<init>(Unknown Source) at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38) where ExtendedArrayList:38 is new
Is there some interface that will allow for iteraction of arrays and java.util.Lists? Seeing
Found this code on http://www.docjar.com/html/api/java/util/HashMap.java.html after searching for a HashMap implementation. 264 static int
The (very outdated) page for LZO contains a link to a Java implementation. There
There seems to be a bug in the Java varargs implementation. Java can't distinguish
Is there any other implementation (e.g. in an OSS project) of a Java SecurityManager
Is there a standard Java (1.5+) implementation (i.e. no 3rd party) of a collection

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.