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中,不需要它吗?