Java: Add HashMap to ArrayList for Talend
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
add a comment |
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
add a comment |
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
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
java
asked Nov 10 at 16:59
Aavik
233316
233316
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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");
}});
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
answered Nov 10 at 17:06
Pushpesh Kumar Rajwanshi
4,7891826
4,7891826
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
add a comment |
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
add a comment |
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");
}});
add a comment |
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");
}});
add a comment |
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");
}});
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");
}});
answered Nov 10 at 17:07
Sand
727112
727112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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