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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:20:56+00:00 2026-06-05T00:20:56+00:00

I want to iterate through the values of a Hashtable, which has a large

  • 0

I want to iterate through the values of a Hashtable, which has a large amount of data (apx. 1 GB). For that, I am using:

Hashtable<String,Object> myHashtable = new Hashtable<String,Object>;

// Fill the Hashtable here...

// Get the values as a Collection:
Collection<Object> myValues = myHashtable.values();

// Get the values as an array:
ArrayList<Object> myArray = myValues.toArray();

// Iterate through the values here...

So, my question is: Am I multiplying the data stored? Does I have 3 copies of the same values stored in RAM (one copy in the Hashtable, one copye in the Collection, and one copy in the ArrayList)?

If the answer is yes, I copied the data, is there a way to iterate through the values of the Hashtable without duplicating the data?

If the answer is no, then does that mean the Collection stores pointers? In that case, if I modify the data in the Hashtable after having created the Collection, does the Collection reflect that change? (same question for the ArrayList).

Thanks!

  • 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-06-05T00:20:58+00:00Added an answer on June 5, 2026 at 12:20 am

    The values() method does not duplicate data, as per the documentation, it returns a view of the values in the map – meaning: if you change the elements in myValues then the changes will be reflected on the original map.

    On the other hand, toArray() does duplicate data, (and it returns an array, not an ArrayList as implied by your code) because it creates a new array with a shallow copy of the elements in myValues. Also, because the array holds references to the elements in the original map, if the objects are mutable changes on them will be reflected on the map – but if you modify the array itself (say, setting to null one of its elements) that change won’t be reflected on the map.

    The simplest way to iterate through the values of a map without creating additional copies of them is to use an iterator on the values:

    for (Object val : myHashtable.values()) {
        // do something with each value
    }
    

    And remember, because the values in the map, the contents of myValues and the contents of myArray are all references to the same objects, any change you make on them will be reflected on the others as well (assuming they’re mutable.)

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

Sidebar

Related Questions

jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
I want to iterate through my model values. Following is what I did to
Basically I have a list of methods that I want to iterate through, call
I have a NameValueCollection , and want to iterate through the values. Currently, I’m
I want to iterate through a set of specific values. Simple example below program
I have two integer arrays which contain numeric values. I want to look through
I'm trying to find a way to iterate through an enum's values while using
I want to iterate through a table/view and then kick off some process (e.g.
I want to iterate through all 5 character combinations of 0-9, a-z. I worked
I want to iterate through store and make grid columns dynamically. When I use

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.