Java: Add HashMap to ArrayList for Talend









up vote
2
down vote

favorite












I am using Talend tJavaFlex component where there is start code(runs once in the beginning), main code(runs for every row), end code(runs once at end).



**In the start code(create an empty list):**
java.util.List sharedList=new java.util.ArrayList<>();

**In the main code(create HashMap for each row and add to list):**
Consider each row has fields: startId, endID, time, flag.

sharedList.add(new java.util.HashMap<String, String>("startId",row1.startId));
<I am not sure how to handle this part>

**In end code(expose the list to other components)**
System.out.print(sharedList.size());


Could you suggest how to create HashMap for each row and add to list.










share|improve this question

























    up vote
    2
    down vote

    favorite












    I am using Talend tJavaFlex component where there is start code(runs once in the beginning), main code(runs for every row), end code(runs once at end).



    **In the start code(create an empty list):**
    java.util.List sharedList=new java.util.ArrayList<>();

    **In the main code(create HashMap for each row and add to list):**
    Consider each row has fields: startId, endID, time, flag.

    sharedList.add(new java.util.HashMap<String, String>("startId",row1.startId));
    <I am not sure how to handle this part>

    **In end code(expose the list to other components)**
    System.out.print(sharedList.size());


    Could you suggest how to create HashMap for each row and add to list.










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am using Talend tJavaFlex component where there is start code(runs once in the beginning), main code(runs for every row), end code(runs once at end).



      **In the start code(create an empty list):**
      java.util.List sharedList=new java.util.ArrayList<>();

      **In the main code(create HashMap for each row and add to list):**
      Consider each row has fields: startId, endID, time, flag.

      sharedList.add(new java.util.HashMap<String, String>("startId",row1.startId));
      <I am not sure how to handle this part>

      **In end code(expose the list to other components)**
      System.out.print(sharedList.size());


      Could you suggest how to create HashMap for each row and add to list.










      share|improve this question













      I am using Talend tJavaFlex component where there is start code(runs once in the beginning), main code(runs for every row), end code(runs once at end).



      **In the start code(create an empty list):**
      java.util.List sharedList=new java.util.ArrayList<>();

      **In the main code(create HashMap for each row and add to list):**
      Consider each row has fields: startId, endID, time, flag.

      sharedList.add(new java.util.HashMap<String, String>("startId",row1.startId));
      <I am not sure how to handle this part>

      **In end code(expose the list to other components)**
      System.out.print(sharedList.size());


      Could you suggest how to create HashMap for each row and add to list.







      java






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 16:59









      Aavik

      230314




      230314






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          You need to correct your sharedList declaration from,



          java.util.List sharedList=new java.util.ArrayList<>();


          to



          java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>();


          And your main code should be written something like this,



          Map<String, String> rowDataMap = new HashMap<String, String>();
          rowDataMap.put("startId",row1.startId);
          rowDataMap.put("endID",row1.endID);
          rowDataMap.put("time",row1.time);
          rowDataMap.put("flag",row1.flag);
          sharedList.add(rowDataMap);


          Let me know if this looks fine and/or if you have any other queries.






          share|improve this answer




















          • Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
            – Aavik
            Nov 10 at 20:13











          • Yes this is how you need to declare your sharedList object where you want to store all Map entries.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:14










          • Thanks. Let me try this at office. The software is in office desktop.
            – Aavik
            Nov 10 at 20:17










          • Oh ok, sure. Let me know if you run into any issues further.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:18










          • Glad to help :)
            – Pushpesh Kumar Rajwanshi
            Nov 11 at 10:36

















          up vote
          1
          down vote













          You can create and initialize a HashMap and add it to a List at once like this,



          List list = new ArrayList();

          list.add(new HashMap()
          put("a", "b");
          );





          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241278%2fjava-add-hashmap-to-arraylist-for-talend%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            You need to correct your sharedList declaration from,



            java.util.List sharedList=new java.util.ArrayList<>();


            to



            java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>();


            And your main code should be written something like this,



            Map<String, String> rowDataMap = new HashMap<String, String>();
            rowDataMap.put("startId",row1.startId);
            rowDataMap.put("endID",row1.endID);
            rowDataMap.put("time",row1.time);
            rowDataMap.put("flag",row1.flag);
            sharedList.add(rowDataMap);


            Let me know if this looks fine and/or if you have any other queries.






            share|improve this answer




















            • Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
              – Aavik
              Nov 10 at 20:13











            • Yes this is how you need to declare your sharedList object where you want to store all Map entries.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:14










            • Thanks. Let me try this at office. The software is in office desktop.
              – Aavik
              Nov 10 at 20:17










            • Oh ok, sure. Let me know if you run into any issues further.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:18










            • Glad to help :)
              – Pushpesh Kumar Rajwanshi
              Nov 11 at 10:36














            up vote
            1
            down vote













            You need to correct your sharedList declaration from,



            java.util.List sharedList=new java.util.ArrayList<>();


            to



            java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>();


            And your main code should be written something like this,



            Map<String, String> rowDataMap = new HashMap<String, String>();
            rowDataMap.put("startId",row1.startId);
            rowDataMap.put("endID",row1.endID);
            rowDataMap.put("time",row1.time);
            rowDataMap.put("flag",row1.flag);
            sharedList.add(rowDataMap);


            Let me know if this looks fine and/or if you have any other queries.






            share|improve this answer




















            • Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
              – Aavik
              Nov 10 at 20:13











            • Yes this is how you need to declare your sharedList object where you want to store all Map entries.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:14










            • Thanks. Let me try this at office. The software is in office desktop.
              – Aavik
              Nov 10 at 20:17










            • Oh ok, sure. Let me know if you run into any issues further.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:18










            • Glad to help :)
              – Pushpesh Kumar Rajwanshi
              Nov 11 at 10:36












            up vote
            1
            down vote










            up vote
            1
            down vote









            You need to correct your sharedList declaration from,



            java.util.List sharedList=new java.util.ArrayList<>();


            to



            java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>();


            And your main code should be written something like this,



            Map<String, String> rowDataMap = new HashMap<String, String>();
            rowDataMap.put("startId",row1.startId);
            rowDataMap.put("endID",row1.endID);
            rowDataMap.put("time",row1.time);
            rowDataMap.put("flag",row1.flag);
            sharedList.add(rowDataMap);


            Let me know if this looks fine and/or if you have any other queries.






            share|improve this answer












            You need to correct your sharedList declaration from,



            java.util.List sharedList=new java.util.ArrayList<>();


            to



            java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>();


            And your main code should be written something like this,



            Map<String, String> rowDataMap = new HashMap<String, String>();
            rowDataMap.put("startId",row1.startId);
            rowDataMap.put("endID",row1.endID);
            rowDataMap.put("time",row1.time);
            rowDataMap.put("flag",row1.flag);
            sharedList.add(rowDataMap);


            Let me know if this looks fine and/or if you have any other queries.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 17:06









            Pushpesh Kumar Rajwanshi

            2,3601721




            2,3601721











            • Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
              – Aavik
              Nov 10 at 20:13











            • Yes this is how you need to declare your sharedList object where you want to store all Map entries.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:14










            • Thanks. Let me try this at office. The software is in office desktop.
              – Aavik
              Nov 10 at 20:17










            • Oh ok, sure. Let me know if you run into any issues further.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:18










            • Glad to help :)
              – Pushpesh Kumar Rajwanshi
              Nov 11 at 10:36
















            • Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
              – Aavik
              Nov 10 at 20:13











            • Yes this is how you need to declare your sharedList object where you want to store all Map entries.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:14










            • Thanks. Let me try this at office. The software is in office desktop.
              – Aavik
              Nov 10 at 20:17










            • Oh ok, sure. Let me know if you run into any issues further.
              – Pushpesh Kumar Rajwanshi
              Nov 10 at 20:18










            • Glad to help :)
              – Pushpesh Kumar Rajwanshi
              Nov 11 at 10:36















            Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
            – Aavik
            Nov 10 at 20:13





            Would this work ? java.util.List<Map<String, String>> sharedList=new java.util.ArrayList<Map<String, String>>(); sharedList.add(new java.util.HashMap() put("startId",row1.startId); put("endID",row1.endID); put("time",row1.time); put("flag",row1.flag); );
            – Aavik
            Nov 10 at 20:13













            Yes this is how you need to declare your sharedList object where you want to store all Map entries.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:14




            Yes this is how you need to declare your sharedList object where you want to store all Map entries.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:14












            Thanks. Let me try this at office. The software is in office desktop.
            – Aavik
            Nov 10 at 20:17




            Thanks. Let me try this at office. The software is in office desktop.
            – Aavik
            Nov 10 at 20:17












            Oh ok, sure. Let me know if you run into any issues further.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:18




            Oh ok, sure. Let me know if you run into any issues further.
            – Pushpesh Kumar Rajwanshi
            Nov 10 at 20:18












            Glad to help :)
            – Pushpesh Kumar Rajwanshi
            Nov 11 at 10:36




            Glad to help :)
            – Pushpesh Kumar Rajwanshi
            Nov 11 at 10:36












            up vote
            1
            down vote













            You can create and initialize a HashMap and add it to a List at once like this,



            List list = new ArrayList();

            list.add(new HashMap()
            put("a", "b");
            );





            share|improve this answer
























              up vote
              1
              down vote













              You can create and initialize a HashMap and add it to a List at once like this,



              List list = new ArrayList();

              list.add(new HashMap()
              put("a", "b");
              );





              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                You can create and initialize a HashMap and add it to a List at once like this,



                List list = new ArrayList();

                list.add(new HashMap()
                put("a", "b");
                );





                share|improve this answer












                You can create and initialize a HashMap and add it to a List at once like this,



                List list = new ArrayList();

                list.add(new HashMap()
                put("a", "b");
                );






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 17:07









                Sand

                4398




                4398



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241278%2fjava-add-hashmap-to-arraylist-for-talend%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto