Java:将HashMap添加到Talend的ArrayList中
我使用的是Talend tJavaFlex组件,其中有开始代码(开头运行一次)、主代码(每行运行一次)、结束代码(结尾运行一次)
**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());
您能建议如何为每一行创建HashMap并添加到列表中吗
# 1 楼答案
您可以创建并初始化一个
HashMap
,然后立即将其添加到List
中,如下所示# 2 楼答案
您需要更正您的sharedList声明
到
你的主代码应该是这样写的
让我知道这看起来是否合适和/或您是否有任何其他疑问