如何将Set <string>值添加到for循环中的List?</string>

时间:2012-05-08 21:53:29

标签: java

我想迭代accountset List<AccountTO>的值并设置为AccountID

实际上在accountset我得到了值:100,101,102我想将这些值添加到List<AccounTO>并将其设置为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("-")));
}

1 个答案:

答案 0 :(得分:1)

如果我正确理解了这个问题,那应该很简单:

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

for (String string : group.getAccounts().keySet()){
            AssetAllocationTO al = new AssetAllocationTO();
            al.setAccountID(string);
            someList.add(al);
}