www.webdeveloper.com
Results 1 to 4 of 4

Thread: HashMap

  1. #1
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,736

    HashMap

    I don't know if a hashmap is the right variable type for what I am trying to do.
    I'm trying to create an array. The keys are big integers (can be up to 4 billion) that are not in sequence. The values are 4 figure integers.
    PHP Code:
    Map<Integer,IntegerVname = new HashMap<Integer,Integer>();
    Vname.put(0x80e4985d,11); // plus 49,000 more 
    I get a compile error: code too large.
    What's going wrong? Is there a better way to do this?

  2. #2
    Join Date
    Jan 2007
    Posts
    85
    Java ints are 32 bits, and are always signed. So their max value is 2,147,483,647 (which is smaller than 0x80e4985d). Trying making your hashmap <Long,Integer>. Longs can be much bigger. check out this website http://www.idevelopment.info/data/Pr...ive_Types.html

  3. #3
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,736
    Quote Originally Posted by potterd64
    Java ints are 32 bits, and are always signed. So their max value is 2,147,483,647 (which is smaller than 0x80e4985d).
    Hi. Thanks for the link. The number is not out of bounds for an integer value. A max value of 2,147,483,647 represents 31 bits leaving 1 bit to represent the sign (+/-). That means 0x80e4985d as an int represents -2132502435 which is correct in this case.
    PHP Code:
    class MyTest {
        public static 
    void main(String[] args) {
            
    System.out.println(0x80e4985d); // -2132502435
        
    }

    What the problem seems to be is the size of the HashMap and loading it statically from the class. I really want to load it from a file but I am new to Java and don't know how. Can you point me in the right direction?

  4. #4
    Join Date
    Jan 2007
    Posts
    85
    right that makes sense. I don't know how to load a hashmap from a file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles