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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:35:47+00:00 2026-05-23T09:35:47+00:00

In the project I am working on, I have a 2D ArrayList which represents

  • 0

In the project I am working on, I have a 2D ArrayList which represents some data:

private ArrayList<ArrayList<T>> data = null;

Now I need to return this ArrayList to some object, in order to let the object inspect it, but not modify it.

I found in the following post that a 2D ArrayList needs to be wrapped separately by the unmodifiable wrapper, but it does not mention how to do it:

Does the unmodifiable wrapper for java collections make them thread safe?

So my problem is: how to return an immutable 2D ArrayList from an existing 2D ArrayList? And in addition, what is the fastest way, since the data could be large in practice?

Thanks for all the inputs!

  • 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-23T09:35:48+00:00Added an answer on May 23, 2026 at 9:35 am

    Use the Collections.unmodifiableList method:

    ArrayList<ArrayList<String>> source = new ArrayList<ArrayList<String>>();
    List<ArrayList<String>> out = Collections.unmodifiableList(source);
    

    Calling Collections.unmodifiableList on the source collection, does not make each nested list unmodifiable. You’ll need to do this recursively on the list, if you want all nested lists to be unmodifiable. So:

    ArrayList<ArrayList<String>> source = new ArrayList<ArrayList<String>>();
    List<List<String>> temp = new ArrayList<List<String>>();
    for (ArrayList<String> list : source) {
        temp.add(Collections.unmodifiableList(list));
    }
    List<List<String>> out = Collections.unmodifiableList(temp);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a recent project I have been working on in C#/ASP.NET I have some
We have need for a rating system in a project we are working on,
I have been working with Struts for some time, but for a project I
I have a large project which was originally written in C#1.1 and is now
I have this project i'm working on and id like to add a really
I project I have been working on has now been split between me and
Hi All I have a project working in PHP which is divided in an
I have a bonita open studio project working great. Now, I don't know how
Many areas in a project I'm working on have a simple timeout check which
I have a working copy of my project, checked out using Subversion 1.5.1. When

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.