Results 1 to 3 of 3

Thread: [java] extract the value from a HashMap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [java] extract the value from a HashMap

    Hello my situation is that:
    Qt Code:
    1. Vector<Word> _words = new Vector<Word>();
    2. //fill the vector
    3. Map<String, Integer> tham = new HashMap();
    4. //fill the map
    5. ..................................
    6. for ( String w : _words) {
    7. Collection c = tham.values();
    8. Iterator it= c.iterator();
    9. int value = 0;
    10. for ( String s : tham.keySet() ) {
    11. System.out.println(" -- string -- " + s);
    12. if ( s.equals( w )) {
    13. System.out.println(" -- string -- " + s);
    14. value = (Integer) it.next();
    15. }
    16. else it.next();
    17. }
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    This should work but it very slow. Is there a way to retrieve the Integer value of the Map with iterate on 'tham' all the times?

    thanks,
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: [java] extract the value from a HashMap

    sorry, the Vector is made by String:
    Vector<String> .....
    Regards

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [java] extract the value from a HashMap

    what exactly are you trying to do? didn't understand the question, sorry.

    use containsKey to check if the hashmap contains an entry, or just call get - it returns null if the key was not in the hashmap.
    Do not iterate over a map when you dont have to.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.