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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:24:27+00:00 2026-05-30T04:24:27+00:00

ArrayList’s Iterator class ArrayList.Itr is private, so I can’t subclass that guy. The things

  • 0

ArrayList’s Iterator class ArrayList.Itr is private, so I can’t subclass that guy.

The things ArrayList.Itr access in ArrayList are private, so I cannot provide my own implementation.

The only way I can see how to do this is to subclass ArrayList, override iterator(), take that iterator and wrap & delegate it to my own Iterator object that denies access to remove. (Or wrap and delegate ArrayList itself and do the same thing)

Collections.unmodifiableList does the same thing, basically.

But this would cause two objects to be created each and every time MyArrayList.iterator() is called, which in my environment is suboptimal.

Ideas?

edit:

In this environment, GCing small objects is a major major problem. This environment calls list iterators hundreds of millions of times in very short periods. We need as little GC thrashing as possible. This is not premature optimization. This is very late optimization. This is not some toy app. This is a clustered web-scale system that is running at the absolute limit of the hardware.

  • 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-30T04:24:29+00:00Added an answer on May 30, 2026 at 4:24 am

    Collections.unmodifiable list, as you mention, is probably the best way to go. I doubt that you have indeed profiled your program as a whole and found out that the creation of iterators is indeed a bottle neck in the execution.

    Actually, Java creates tons and tons of temporary objects. This is not good per see, but due to this it is very optimized to do it efficiently.

    Btw, the fact that you’re trying to access private members of the ArrayList actually smells a little. Why not create an iterator based on size() and get(int index) if you really don’t want to create two objects when iterating over the list?

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

Sidebar

Related Questions

import java.util.ArrayList; import java.util.Arrays; public class Cloud { private ArrayList<Point> points; private double left;
The ArrayList class can only contain references to objects but what happens when you
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I'm storing an ArrayList of Ids in a processing script that I want to
Can an ArrayList of Node contain a non-Node type? Is there a very dirty
I have an arraylist that contains items called Room. Each Room has a roomtype
ArrayList<String> veri1 = new ArrayList<String>(); String[] veri2 = {Fatih, Ferhat, Furkan}; How can I
I have an ArrayList in my Servlet code. Now, I want to show that
I have an ArrayList<MyObject> that may (or may not) contain duplicates of MyObject I
How can I convert ArrayList into string[] in C#?

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.