Results 1 to 2 of 2
  1. #1
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    133
    Rep Power
    0

    Default Object Library Hashmap, Size Questions

    My perfect idea is to have a Hashmap that would increase size each Key & value added, it's almost like a self-increasing array. I mean I could just create a very large Hashmap for me to add objects to anytime I want with a key to be able to find the object. Is this the most efficient way, because I'm trying to make my Object Library compatible with any amount of Objects, however, I know there's a limit to how many values you can have in an array, but it's larger than I'll ever need. I may not be setting my question out clearly, but it's generally a question like Should I create a very large array for me to use eventhough I sometimes may not use all the possible placeholders?

    Let's say I'm making a number storage program, and I may need from 3 to 8 numbers to be stored with a key to find them easily using a Hashmap, rarely I may need below 3 or above 8. So is it efficient for me to create a Hashmap that has 10 placeholders? Or can I make this more efficient. Note, my Library is static. I don't know how to explain this too well because I have a feeling this my question is hard to understand or you'll get the wrong idea. P:

    Regards
    Augustas

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,812
    Rep Power
    5

    Default Re: Object Library Hashmap, Size Questions

    Quote Originally Posted by augustas656 View Post
    Let's say I'm making a number storage program, and I may need from 3 to 8 numbers to be stored with a key to find them easily using a Hashmap, rarely I may need below 3 or above 8. So is it efficient for me to create a Hashmap that has 10 placeholders?
    Either I don't understand your question or you are not clear about hashmaps. You could have N placeholders (buckets?)but how they are placed in the map is determined by their hashcode. Depending on the numbers they could all possibly hash to the same bucket. Either way I don't believe performance is an issue (except it's better than a linear lookup even for small number of entries).

    If you really don't want to have the array backed implementation preallocate the array and rehash when it needs to (based on a threshold) then you could use the LinkedHashMap which dynamically adds buckets when needed.

    Both implementations have their drawbacks. I recommend you check the documentation for both.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Size reduction of jfree library
    By chirayu in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2012, 07:53 AM
  2. Hashmap questions
    By PhQ in forum New To Java
    Replies: 3
    Last Post: 01-22-2012, 09:50 PM
  3. hashmap questions =P
    By santa in forum New To Java
    Replies: 3
    Last Post: 05-31-2011, 02:06 PM
  4. The java Library and other questions
    By Joey in forum New To Java
    Replies: 4
    Last Post: 05-19-2010, 07:21 PM
  5. Questions On Java GUI Library
    By hitmen in forum AWT / Swing
    Replies: 8
    Last Post: 02-26-2009, 11:50 AM

Posting Permissions

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