【发布时间】:2013-12-04 16:59:07
【问题描述】:
我正在使用此代码和 ds list 打印例如:
aaa.(bbb)
aaa.(eee)
ccc.(ddd)
...
我需要它在相同的括号中打印与aaa 相关的字符串,以分隔它们。
例如:aaa.(bbb,eee)
我应该对我的代码进行哪些更改?
我知道代码不完整,但如果我添加所有内容,它会变得复杂很多。目标是在迭代字符串 s 的 templist 时,以上述格式添加 templist 元素。
List<String> templist = new ArrayList<String>() ;
List<String> ds = new ArrayList<String>() ;
String s = "aaa"
String selecfin = null ;
for(int j =0;j<templist.size(); j++){
String selecP = templist.get(j);
selecfin = s+".("+selecP+")";
ds.add(selecfin);
}
【问题讨论】:
-
根据您的代码,除了
aaa.(xxx),它不能打印任何内容。s中的值什么时候变化? -
我建议您创建一个类似 Map
> 的结构,将根 ("aaa", "ccc") 作为键并添加到字符串列表为价值观。