Results 1 to 3 of 3
  1. #1
    TheGame is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default Does Hashmap or Nested Loop use more memory?

    hi, i want to know if a hashmap or a for loop with another nested for loop use more memory?

    in my case, i have a for loop that iterates 10 times and stores entries into the hashmap if appropriate, with key type String and value type Integer, and the number of entries could be somewhere from 3 to 6...

    so does this use more memory compared to a for loop that iterates about 10 times with a nested for loop that also iterates at worst 10 times..

    also, i know the hashmap is faster in this case but does it use more memory?

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Destiny Islands
    Rep Power


    Run a stress test using your code that initiates dozens of hashmaps and watch your computer's memory. Then do the same with the for loops. Or you can print out the memory values with Java's built-in memory functions.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    First off is it really becessary to worry about this at this stage?
    I would argue not.

    Do you need to store the stuff in a Map? If so then store it in a Map.
    To me this sounds like a classic case of over analysing something, something which is unlikely to be a performance bottleneck.

Similar Threads

  1. Explanation of Nested Loop (very strange)
    By Jonotron in forum New To Java
    Replies: 5
    Last Post: 01-09-2011, 03:54 AM
  2. Nested Loop help -- concerning image repetition
    By Submerged in forum Java Applets
    Replies: 0
    Last Post: 03-05-2010, 04:57 AM
  3. can some one help me with nested loop?
    By keycoffee in forum New To Java
    Replies: 10
    Last Post: 01-25-2010, 03:49 AM
  4. nested for loop question
    By javabob in forum New To Java
    Replies: 3
    Last Post: 05-20-2008, 11:00 PM
  5. Nested For Loop
    By yuchuang in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts