Why do we use Map.Entry ?

I have this example of mine where am able to do everything using the entrySet() method, hence I dont see any use of Map.Entry.
public class HashMapDemo {
     public static void main ( String args [])
                  HashMap hm = new HashMap();
                  hm.put("Rohit", new Double(3434.34));
                  hm.put("Rohita", new Double(3435.34));
                 hm.put("Mohit", new Double(123.22));
                 hm.put("Ashish", new Double(1200.34));
                 hm.put("Khariwal", new Double(99.34));
                 hm.put("Pankaj", new Double(-19.34));
                 Set set = hm.entrySet();
                   System.out.println("the value of set is " + set);
                   Iterator i = set.iterator();          
                   while (i.hasNext())
System.out.println(i.next());
         }

jose_an wrote:
What i exactly meant to ask is what's the exact need of Map.Entry inner class in HashMap.
If we can use an iterator then whats the need for Map.EntryYou can iterate over the keys, if all you want is the keys.
You can iterate over the values, if all you want is the values.
You can iterate over the key/value pairs, if you want to process all the pairs.
Map.Entry is not strictly necessary--or at least doesn't need to be made public--but it can be useful. Sure, you could just use keySet() instead of entrySet() and then use each key to get the corresponding value, but if you want to work with both together, it can make for clearer code to have a single object that represents that pairing.
Also, when iterating over a map's key/value pairs, it could be somewhat faster to just iterate over the entrySet, rather than iterating over the keys and then calling get() each time. In most cases, the difference should be negligible, but depending on the map implementation and usage profile, it could be significant.

Similar Messages

  • WHY DONT I USE NOKIA MAPS???

    I am puzzled about Nokia Maps, like why I cant and dont use it!? why am I considering buying Route 66 for £59? and even a TomTom Go One GB? handheld unit??? £100
    hang on a minute!! I have a perfectly good N95-1?? so why dont I use Nokia Maps?? its paid for it should work!! well it requires a GSM network connection as well as GPS, which caines all your credit in no time thats with the maps downloaded! what was the point of selling a GPS enabled reciever phone with all the fancy Maps program but I cant use it like any other normal APP!!!???
    How much does it cost to run? does it deppend on network?
    or ammount of data used, why does it try to download the mao when its already downloaded from Nokia?
    Its mad, I can get a satelite to lock in,and even try to plan routes , but it constantly crashes out, its useless , its a shame!! I paid all that money and I cant use the GPS at all anyone else feel the same??
    N95-1 (8GB-MicroSD),LCG-Audio,Fring,Nimbuzz,Skype,Youtube,iPlayer,Garmin4-GPS.Googlemaps,SkyFire,ZoneTag,Gravity, Sennheiser CX-400-IIs,500-IIs,TR-120 Wireless,HD215'S.AudioTechnica ATX-M50's.BT B-Tube BT Speaker.

    UPDATE:
    Re-installed the same firmware, managed to install MAPS 2.02
    and it all now works until you need it ! i'll explain later.
    SIMPLE MISATKES!:
    Make sure you have the memeory card inserted before the install of MAPS 2.02!
    Make sure your phones Profile is on GENERAL after restoring your backup after upgrading your firmware. Now MAPS 2.02 should load.
    after all this I had to reinstal Nokia Internet Radio Youtube, Fring, AND I installed GOOGLE MOBILE MAPS with a 800kb download over GPRS and it's amazing! need to see a thread dedicated to Google Mobile Maps!
    MAPS 2.02 First off Im very impressed with the new version of MAPS and all its features until you NEED certain things!
    NO MORE ATMS or CASHMACHINES show up, NO MORE WIFI POINTS!!
    how do I fix this?? is this the EXTRAS WE HAVE TO PAY FOR?
    Now I'm in town and I'm dettermind to actualy get a fix and use this thing in town under stress of busy traffic and a busy crowd test! I got a FIX with the Red Icon showing and I looked up a shop and hit go and up pops another box saying The Licence blah blah whats going on?? it always tries to charge me at the most inconvienient time ever!
    I have no idea if I have to subscribe or get billed off my network?
    I have NEVER been able to figure out MAPS :/ like how is it charged? how you subscribe to it? would I need web n walk or surf for a £1 all day on O2 would this help? Its useless otherwise i'm totally perplexed with it. ROute 66 is £59 you install it , it works. or £99 TomTOm 1 Solid State, slim portable, big touch screen, so if after all this setting up time and hassle with MAPS 2 how much will it cost me?
    N95-1 (8GB-MicroSD),LCG-Audio,Fring,Nimbuzz,Skype,Youtube,iPlayer,Garmin4-GPS.Googlemaps,SkyFire,ZoneTag,Gravity, Sennheiser CX-400-IIs,500-IIs,TR-120 Wireless,HD215'S.AudioTechnica ATX-M50's.BT B-Tube BT Speaker.

  • Map.entry

    Hello,
    I'm working with the Collection FrameWork
    When you ask a Map for it's entrySet(), you get a Set of Map.Entry's.
    public static interface Map.Entry
    STATIC,
    Why is this interface static???

    If it hadn't been static, you'd have to have an instance of Map to use the interface. Now you can simply implement Map.Entry.
    Kind regards,
      Levi

  • Compile errors importing Map$Entry

    Hi,
    I trying to compile code written by my client which uses the following syntax
    import java.util.Map$Entry.
    This throws a compilation error :
    cant resolve symbol class Map$Entry
    package : java.util
    The same compile at the client side works. Am i missing some configuration. Also why is the path defined as Map$Entry instead of Map.Entry.
    any help would be greatly appreciated
    thanks and regrads
    Kumar Vellal

    What you're client is trying to do is import a nested class. To do this you use the syntax:
    import A.Enclosing.Nested;Now you can refer to the nested class without refering to the enclosing class (i.e Nested n = new Nested();)
    However - Some compilers don't like this, and I don't like it. You shouldn't import nested classes directly like this.

  • What is the diffrence between  map and map.entry in core java

    what is the diffrence between map and map.entry in core java . where it will be use ful. any one give one example plz.

    A Map contains Map.Entry's
    e.g.
            Map map = new LinkedHashMap(8);
            map.put(new Integer(1), "one");
            map.put(new Integer(2), "two");
            final Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry entry = (Map.Entry) iterator.next();
                System.out.println("key=" + entry.getKey() + ", value=" + entry.getValue());
            }

  • Lots of different errors when using Maps on Linux, help?

    I'm trying to use Maps in one of my programs, but for some reason I get all sorts of different errors when compiling.
    I've tried both my own (very) simple tests of it and also I've copied and pasted the code straight out of the official tutorials.
    //Edit: Ok, I've tried it on several different IDEs, and Netbeans (on both Linux and Windows) and JCreator(on Windows) both work now for whatever reason. The only one I still have problems with is below.
    Here some of the errors I get, and nothing is making sense.
    On a Linux machine, using a simple IDE (Geany):
    MapTest.java:6: not a statement
    Map<String, Integer> m = new TreeMap<String, Integer>();
    ^
    MapTest.java:6: ';' expected
    Map<String, Integer> m = new TreeMap<String, Integer>();
    I don't know why it isn't working.

    What do IDEs have to do with this? It's a compiler error.
    Do you import java.util.Map and java.util.TreeMap?
    Are you using JDK 5 or higher? Generics didn't appear in Java until JDK 5.
    %

  • In iWeb, Why should my Google map be linked to MobileMe

    I have a Google map on my website.
    Now that MobileMe has closed I cannot use Google Maps.
    In iWeb, Why should my Google map be linked to MobileMe when I have never joined MobileMe?
    Any help please

    The Google map widget assets were hosted on MobileMe.
    Use the Google Map code in an HTML Snippet instead.
    Google has a good tutorial for creating basic maps...
    http://maps.google.com/help/maps/getmaps/plot-one.html
    If you want to make changes to the code or add features...
    http://www.iwebformusicians.com/iweb-snippets/map-tutorial.html
    http://www.iwebformusicians.com/iweb-snippets/map.html
    ... or create an info slider...
    http://www.iwebformusicians.com/iweb-snippets/map-2.html

  • Missing "Mapping entry" issue in tranferring Cust/Vendor Master Data

    Hi All,
    We are doing a version upgrade in one of our client for SCM APO (SCM 7.0 SPS 8). We are getting an error while transferring customer/ vendor master data (either in foreground or background) that "No location XXXXXXXX exists for mapping entry XXXXXXX of category 1011 (1010 in case of customer).
    Please provide your valuable help to resolve this issue.
    Thanks.

    Dear Ravi.
    Please use the report ZMATMAP_REORG provided in note 859650 to remove the inconsistencies between /SAPAPO/LOCMAP and /SAPAPO/LOC.
    The number of entries in these both tables should be the same.
    I am not aware of your SCM Release, but it is also relevant for release 4.1, despite the info in the note.Please copy the report in your system and execute it firstly in the test mode.
    I hope this helps you!
    Let me know the outcome of the issue.
    Thank you!
    Will

  • Why is the new mapping so bad?

    Why is he new mapping system so bad and when will it be fixed?

    Apple is constantly working on improving their new Maps service, but until it reaches the level of finesse necessary to be usable, take a look at some alternatives.
    Bing Maps offers a very good maps service with Bird's Eye, a feature similar to Flyover. It's arguably better than Google Maps.
    http://itunes.apple.com/us/app/bing/id345323231?mt=8
    You can use Google Maps by creating a shortcut to the Home Screen with help from the article below.
    http://www.ign.com/articles/2012/09/20/how-to-get-google-maps-on-ios-6
    MapQuest also has a very nice app available.
    http://itunes.apple.com/us/app/mapquest/id316126557?mt=8
    Nokia Maps is another great service that you can add to your Home Screen via a web shortcut.
    http://m.maps.nokia.com
    Waze is another very well reviewed app.
    https://itunes.apple.com/us/app/waze-social-gps-traffic-gas/id323229106?mt=8
    Here's an article detailing how to receive Public Transport directions.
    http://www.wired.com/gadgetlab/2012/09/transit-apps-ios6-woes/?pid=3798
    If you want a YouTube app, Google has made a very improved version available on the App Store.
    http://itunes.apple.com/us/app/youtube/id544007664?mt=8
    If you would like to send a suggestion to Apple, please go to http://www.apple.com/feedback or you can Report a Problem via the Maps app by tapping the bottom right.

  • Why cant i use a bought call-tone bought through I-tones for calling tones for just one of my contacts?

    Why cant i use a bought call-tone bought through I-tones for calling tones for just one of my contacts?

    What makes you believe that you can't? To set a custom ringtone (or SMS tone) for a contact, go to that contact entry, tap the Edit button in the upper right. You can then edit both ringtones and SMS tones for that contact.

  • Why do i have 2 entries for the same event in iCal?

    I have just upgraded to OS Lion, purchased an iPhone 4S and have also moved to iColuds - why do I have 2 entries for all my events in iCal?

    You can just delete the ones you don't want from the document Library. Be careful though, that you do not delete the symbol(s) that are being used on the canvas.
    It's hard to say how you got so many duplicates in the first place without knowing your workflow.
    My guess is that you created a new symbol every time you added something to the canvas, but that is only a guess.
    HTH
    Jim

  • I cannot use maps in india, n thats shame for ios6

    I was trying to use maps on ipad2 and iphone 4, i was helpless to use it. Called up coustmer care and they replied ios6 is not feasible for india. Why? Fr the kind information of apple , india has the greater commercial market of phone users. I was a great fan of apple, but now i regret to be one of.  Apple has to reply on this comment when it can be solve. I am completely relaying on apple product. Instead of concentrating on rubbish publicity u guys should really look at our problem. Rest of the application are good. But maps? The most important thing in apple is missing. Really missing steve jobes hand on it. I request you to please check news papers for the same.

    You cannot downgrade. Do a search in the forum and you will find alternatives that might help you solve the Map problem.
    The easiest one is to add the maps.google.com link to your homescreen. It is not perfect but it works.

  • How to show speed, when only using maps

    Hi
    I have a 5230, I will like to see the speed I am driving, only using map, but no destianation, is that posible and how.
    Br/ 

    Ah, depending on how new the car model is, the speedometer is more accurate.
    Anyway, as of the moment Ovi Maps is incapable of doing what you're asking. However you can however simply put the navigation volume at 0, set a random destination and drive around. Just ignore the blue line in the navigation.
    You do know where you are going, so why dont you just set that as the destination when you drive? I mean, that's what the Nav system is for right?
    If you find my post helpful please click the green star on the left under the avatar. Thanks.

  • Why do we use Feild Symbols

    Hi All
    Breifly explain me why do we use field symbols. and how to use them and where to use them.
    Thanks! in advance

    Hi,
    The new style of definition of internal tables usually doesn't include a header area for the internal table. Furthermore, ABAP Objects will not allow internal tables with header lines. For added performance, instead of declaring a work area--use a field symbol. The work area concept and header line format both require data to be moved from the internal table to the work area or header area. A field symbol is just a pointer that will point to the proper line of the itab. With field symbols, no data needs to be moved. The field symbol just stores the proper memory address to point at the right line. The field symbol can have structure and be made up of fields similar to a work area or header line. Because no data needs to be copied, processing is much faster.
    The keys to the usage are:
    1) Defining the table records and the field symbol in a similar type.
    just an ordinary standard table
    TYPES: BEGIN OF it_vbak_line,
    vbeln LIKE vbak-vbeln,
    vkorg LIKE vbak-vkorg,
    vtweg LIKE vbak-vtweg,
    spart LIKE vbak-spart,
    kunnr LIKE vbak-kunnr,
    END OF it_vbak_line.
    DATA: it_vbak TYPE TABLE OF it_vbak_line.
    FIELD-SYMBOLS: <it_vbak_line> TYPE it_vbak_line.
    or as a screaming fast hash table for keyed reads
    TYPES: BEGIN OF it_vbpa_line,
    vbeln LIKE vbak-vbeln,
    kunnr LIKE vbak-kunnr,
    END OF it_vbpa_line.
    DATA: it_vbpa TYPE HASHED TABLE OF it_vbpa_line
    WITH UNIQUE KEY vbeln.
    FIELD-SYMBOLS: <it_vbpa_line> TYPE it_vbpa_line.
    2) In ITAB processing, utilize the ASSIGNING command.
    loop example
    LOOP AT it_vbak ASSIGNING <it_vbak_line>.
    look at records--populate it_zpartner
    read example
    READ TABLE it_vbpa ASSIGNING <it_vbpa_line>
    WITH TABLE KEY vbeln = <it_vbak_line>-vbeln.
    3) Refer to the field symbol's fields in the loop or after the read.
    wa_zpartner-vkorg = <it_vbak_line>-vkorg.
    wa_zpartner-vtweg = <it_vbak_line>-vtweg.
    wa_zpartner-spart = <it_vbak_line>-spart.
    wa_zpartner-kunag = <it_vbak_line>-kunnr.
    wa_zpartner-kunwe = <it_vbpa_line>-kunnr.
    See the code example below for further detail. The code was written in R/3 4.6C and should work for all 4.x versions.
    Code
    REPORT z_cnv_zshipto_from_hist          NO STANDARD PAGE HEADING
                                            LINE-SIZE 132
                                            LINE-COUNT 65
                                            MESSAGE-ID z1.
    Program Name: ZSHIPTO from History             Creation: 07/23/2003  *
    SAP Name    : Z_CNV_ZSHIPTO_FROM_HIST           Application: SD      *
    Author      : James Vander Heyden               Type: 1              *
    Description :  This program reads tables VBAK & VBPA and populates   *
    ZPARTNER. ZPARTNER table is read in by ZINTSC06. ZINTSC06 updates    *
    the ZSHIPTO relationships.                                           *
    Inputs:  Selection Screen                                            *
    Outputs:                                                             *
    External Routines                                                    *
      Function Modules:                                                  *
      Transactions    :                                                  *
      Programs        :                                                  *
    Return Codes:                                                        *
    Ammendments:                                                         *
       Programmer        Date     Req. #            Action               *
    ================  ==========  ======  ===============================*
    J Vander Heyden   07/23/2003  PCR     Initial Build                  *
    DATA DICTIONARY TABLES                                               *
    TABLES:
      zpartner.
    SELECTION SCREEN LAYOUT                                              *
    PARAMETERS: p_load   RADIOBUTTON GROUP a1 DEFAULT 'X',
                p_deltab  RADIOBUTTON GROUP a1.
    SELECTION-SCREEN SKIP 2.
    SELECT-OPTIONS: s_vkorg  FOR zpartner-vkorg MEMORY ID vko OBLIGATORY
                                 NO INTERVALS NO-EXTENSION,
                    s_vtweg  FOR zpartner-vtweg MEMORY ID vtw OBLIGATORY
                                 NO INTERVALS NO-EXTENSION,
                    s_spart  FOR zpartner-spart MEMORY ID spa OBLIGATORY
                                 NO INTERVALS NO-EXTENSION.
    INTERNAL TABLES                                                      *
    TYPES: BEGIN OF it_vbak_line,
            vbeln LIKE vbak-vbeln,
            vkorg LIKE vbak-vkorg,
            vtweg LIKE vbak-vtweg,
            spart LIKE vbak-spart,
            kunnr LIKE vbak-kunnr,
          END OF it_vbak_line.
    DATA: it_vbak TYPE TABLE OF it_vbak_line.
    FIELD-SYMBOLS: <it_vbak_line>  TYPE it_vbak_line.
    TYPES: BEGIN OF it_vbpa_line,
            vbeln LIKE vbak-vbeln,
            kunnr LIKE vbak-kunnr,
          END OF it_vbpa_line.
    DATA: it_vbpa TYPE HASHED TABLE OF it_vbpa_line
                       WITH UNIQUE KEY vbeln.
    FIELD-SYMBOLS: <it_vbpa_line>  TYPE it_vbpa_line.
    DATA: it_zpartner TYPE TABLE OF zpartner.
    DATA: wa_zpartner TYPE zpartner.
    STRUCTURES                                                           *
    VARIABLES                                                            *
    DATA:  z_mode   VALUE 'N',
           z_commit TYPE i,
           z_good   TYPE i,
           z_bad    TYPE i.
    CONSTANTS                                                            *
    SELECTION-SCREEN HELP                                                *
    INITIALIZATION                                                       *
    INITIALIZATION.
    AT LINE SELECTION                                                    *
    AT LINE-SELECTION.
    AT SELECTION SCREEN                                                  *
    AT SELECTION-SCREEN.
    START-OF-SELECTION                                                   *
    START-OF-SELECTION.
      IF p_load = 'X'.
        PERFORM select_records.
        PERFORM process_itab.
      ELSE.
        PERFORM delete_table.
      ENDIF.
    END-OF-SELECTION                                                     *
    END-OF-SELECTION.
    *&      Form  DELETE_TABLE
          text
    FORM delete_table.
      DATA:  w_answer.
      CLEAR: w_answer.
      CALL FUNCTION 'POPUP_TO_CONFIRM'
           EXPORTING
                titlebar              = text-002
            DIAGNOSE_OBJECT       = ' '
                text_question         = text-003
                text_button_1         = text-004
                icon_button_1         = 'ICON_OKAY'
                text_button_2         = text-005
                icon_button_2         = 'ICON_CANCEL'
                default_button        = '2'
                display_cancel_button = ''
            USERDEFINED_F1_HELP   = ' '
            START_COLUMN          = 25
            START_ROW             = 6
            POPUP_TYPE            =
          IMPORTING
               answer                = w_answer.
       TABLES
            PARAMETER             =
       EXCEPTIONS
            TEXT_NOT_FOUND        = 1
            OTHERS                = 2
      IF w_answer = 1.
        DELETE FROM zpartner
       WHERE vkorg IN s_vkorg
         AND vtweg IN s_vtweg
         AND spart IN s_spart.
        MESSAGE i398(00) WITH 'Records deleted from table: '
                              sy-dbcnt
      ENDIF.
    ENDFORM.                    " DELETE_TABLE
    *&      Form  SELECT_RECORDS
          text
    FORM select_records.
    get vbaks
      CLEAR: it_vbak.
      SELECT vbeln vkorg vtweg spart kunnr
        FROM vbak
        INTO CORRESPONDING FIELDS OF TABLE it_vbak
       WHERE vkorg IN s_vkorg
         AND vtweg IN s_vtweg
         AND spart IN s_spart
         AND auart = 'TA'.
    get vbpa we's
      CLEAR: it_vbpa.
      SELECT *
        FROM vbpa
        INTO CORRESPONDING FIELDS OF TABLE it_vbpa
        FOR ALL ENTRIES IN it_vbak
       WHERE vbeln = it_vbak-vbeln
         AND posnr = '000000'
         AND parvw = 'WE'.
    ENDFORM.                    " SELECT_RECORDS
    *&      Form  PROCESS_ITAB
    attempt post goods issue for all entries.
    FORM process_itab.
      LOOP AT it_vbak ASSIGNING <it_vbak_line>.
    look at records--populate it_zpartner
        READ TABLE it_vbpa ASSIGNING <it_vbpa_line>
                    WITH TABLE KEY  vbeln   = <it_vbak_line>-vbeln.
        IF sy-subrc = 0.
          CLEAR: wa_zpartner.
          wa_zpartner-mandt = sy-mandt.
          wa_zpartner-vkorg = <it_vbak_line>-vkorg.
          wa_zpartner-vtweg = <it_vbak_line>-vtweg.
          wa_zpartner-spart = <it_vbak_line>-spart.
          wa_zpartner-kunag = <it_vbak_line>-kunnr.
          wa_zpartner-kunwe = <it_vbpa_line>-kunnr.
          APPEND wa_zpartner TO it_zpartner.
        ENDIF.
      ENDLOOP.
      SORT it_zpartner BY mandt vkorg vtweg spart kunag kunwe..
      DELETE ADJACENT DUPLICATES FROM it_zpartner.
    do a mass table update.
      INSERT zpartner FROM TABLE it_zpartner.
      IF sy-subrc = 0.
        MESSAGE s398(00) WITH 'Inserted records: ' sy-dbcnt.
      ENDIF.
    ENDFORM.                    " PROCESS_ITAB
    reward if helpful,
    kushagra

  • Compile error import java.util.map$entry

    Hi,
    I am trying to compile code which imports the following package
    import java.util.Map$Entry.
    The error thrown up is : cant resolve symbol Map$Entry. Why is there a $ in the package import path and is there some configuration required to compile the file.
    I am not allowed to change the code. Does anyone have an idea on how this problem can be solved.
    Thanks and regards
    Kumar Vellal

    Btw java docs for the interface are available at:
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Map.Entry.html
    Changing the import should probably help compile the code, but without changing the import .. need to check. This is just from what i remember now. Lets see if anyone else comments on this.

Maybe you are looking for

  • Trouble with isight and chat programs

    I just bought an imac g5 with the integrated isight. I have been using msn mac version, but i cant figure out how to use my isight as a webcam. Is that possible to use the isight in that way? Do i need a special version of msn messenger? Any help wou

  • Unibody MacBook Pro sensitive spacebar

    Just recently I've noticed my MacBook Pro picks up spacebar input on nothing more than a brush of the key. It's not sticky, just stupidly sensitive to touches. Unfortunately this means whenever I close the lid, the spacebar input is registered and th

  • How to reduce the time..?

    Hi All, this statement below is taking lot of time how can i reduce the time ....? cheers sundeep select * from zausfu where vbeln in so_vbeln                     AND wadat_ist IN so_wadat                     AND aland IN so_eland                    

  • Windows 7 Sync issues

    Ever since getting a new comp a couple of months ago I've been unable to sync my iphone 3gs with my computer. Looking on the web has revealed that this is a well known problem with windows 7 and iphones. however i am yet to find a solution. am i bein

  • Why always report this error

    An unexpected exception has been detected in native code outside the VM. Unexpected Signal : 11 occurred at PC=0x403db221 Function name=(N/A) Library=/lib/i686/libc.so.6 NOTE: We are unable to locate the function name symbol for the error just occurr