Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何添加集合<;字符串>;for循环中列表的值?_Java - Fatal编程技术网

Java 如何添加集合<;字符串>;for循环中列表的值?

Java 如何添加集合<;字符串>;for循环中列表的值?,java,Java,我想迭代accountset列表的值,并设置为AccountID 实际上,在accountset中,我正在获取值:100101102我想将这些值添加到列表中,并将它们设置为AccountID,并将其传递给服务调用。有什么我可以做的,或者其他的程序 for(String s :group.getAccounts().keySet()) { System.out.println("===="+s.lastIndexOf("-")); System.out.println("sub"+

我想迭代
accountset
列表的值
,并设置为
AccountID

实际上,在
accountset
中,我正在获取值:
100101102
我想将这些值添加到
列表中
,并将它们设置为
AccountID
,并将其传递给服务调用。有什么我可以做的,或者其他的程序

for(String s :group.getAccounts().keySet())
{
    System.out.println("===="+s.lastIndexOf("-"));
    System.out.println("sub"+s.substring(0,s.lastIndexOf("-")));
    accountSet.add(s.substring(0, s.lastIndexOf("-")));
}

如果我正确理解了这个问题,它应该相当简单:

List<AssetAllocationTO> someList = new ArrayList<AssetAllocationTO>();

for (String string : group.getAccounts().keySet()){
            AssetAllocationTO al = new AssetAllocationTO();
            al.setAccountID(string);
            someList.add(al);
}
List-someList=new-ArrayList();
for(字符串:group.getAccounts().keySet()){
AssetLocationTo al=新的AssetLocationTo();
al.setAccountID(字符串);
someList.add(al);
}

问题结构非常糟糕,如果您在写问题时花点力气,解决方案可能很简单better@prashanth请重新格式化您的问题并更好地解释它,我不明白什么是输入以及应该使用什么代码doSet accountSet=new HashSet();我需要将accountset添加到列表中什么类型的对象是
AssetLocationTo
它由私有字符串AccountId组成值在accountset中,不需要它吗?