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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:35:39+00:00 2026-06-01T04:35:39+00:00

I’m pretty new to Java so sorry if this is super basic. Basically I

  • 0

I’m pretty new to Java so sorry if this is super basic. Basically I have some data in a array list and it works fine but in a later part of my program I need to read the list and it takes a long time because the list becomes very large. So I thought I could take certain parts of the array list(thats needed later) into a hash map that I can extract that section of the array list later from(hopefully that makes sense).

I first create the array list with all the data I want(I have a loop and call each data thats created in a single loop data_cache_local_loop):

HashMap hashmap_of_values = new HashMap(); //hashmap of arraylist
for (int i = 0; i<100; i++) {
....program logic and more loops
Set uniqie_T_cache = new HashSet(T_cache_local_loop); //make values unique
hashmap_of_values.put(i, new ArrayList(uniqie_T_cache));
}

Then later on when I need the data I extract it like this:

List t = new ArrayList();
t.add(hashmap_of_values.get(i));

But my program fails and I’m not sure exactly why. When I print out the size of hashmap_of_values I get the number of i’s I’m expecting but when I print out the number of T it only shows one(when I run the program it says T_cache_local_loop has hundreds of items).

Can anyone suggest to me what I’m doing wrong? I’m not 100% but I think I maybe looking at the array list I add as a single item but I’m unsure of what I’m doing wrong.

  • 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-01T04:35:41+00:00Added an answer on June 1, 2026 at 4:35 am

    You should really be using generics — it’d help you a lot, and make these issues much more obvious — but for the moment your problem is that that line should be

    List t = (List) hashmap_of_values.get(i);
    

    or

    List t = new ArrayList((List) hashmap_of_values.get(i));
    

    to get a copy of the list in the map. What you were doing was creating a list of lists, because hashmap_of_values.get(i) was already a list.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.