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.
java
add a comment |
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.
java
add a comment |
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.
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
230314
230314
add a comment |
add a comment |
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.
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 |
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");
);
add a comment |
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.
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 |
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.
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 |
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.
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
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
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 |
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");
);
add a comment |
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");
);
add a comment |
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");
);
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
4398
4398
add a comment |
add a comment |
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