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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:15:46+00:00 2026-05-23T16:15:46+00:00

I am currently building an LRU cache where I need to store the last

  • 0

I am currently building an LRU cache where I need to store the last N inserted items. Items will be inserted frequently (i.e. many write operations) and read operations will typically return a large number of events always strictly in sequence albeit starting at an arbitrary point in the cache. For example, suppose the cache contains events:

[1, 2, 3, 4, 5, 6]

A legal read operation would be to return an iterator over events [2, 3, 4].

Due to read operations potentially being long-lived I’d like to use a data structure where I can safely iterate over a logical copy of the sequence for each read attempt, thus preventing a cache read from holding up any subsequent writes. However, using a vanilla Java ArrayList or LinkedList implies a large overhead in making a full copy.

My question: Are there any 3rd party Java libraries that provide immutable data structures similar to Scala, whereby attempts to modify the data structure return a new immutable copy (which is in fact based on the original data structure and hence the copy operation is very fast)? Obviously the data structure could not conform to the Java Collections API as operations like add(T) would need to return the new collection (rather than void).

(Please no comments / answers citing this as a case of premature optimisation.)

Thanks in advance.

Note

Guava’s ImmutableList nearly achieves what I need: It allows to you call copyOf where the copy typically references the original (avoiding performing an actual copy). Unfortunately you can’t go the other way and add an item to the list and get back a copy that includes the new element.

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

    Functional Java comes in the form of a library (not a different language) and provides immutable collections. Not sure if it’ll fit your needs but worth a try.

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

Sidebar

Related Questions

I'm currently building a console app for a school project and I really need
I'm currently building an app where i need somewhat of a lookup control. How
I am currently building an API which will be used by a webservice. I
Currently building a WPF app that will run in an environment where the user
I'm currently building a Java app that could end up being run on many
Currently building an app that runs on mobile phones not related to the issue
I'm currently building a reporting service (WCF) - filled reports are produced using an
I am currently building a measurement unit convertion app for Windows Phone. After setting
I am currently building my project locally using MVC. The user enters some search
We're currently building multiple copies of our Chrome CRX, one for each of our

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.