如何让我的的输出循环的值,并将其添加到我的arraylist
,所以如果我的回路的输出是一样string1
,string2
,string3
我怎么把这个变成我的ArrayList
List<String> tpc = new ArrayList<>();
for(int i = 0; i < topics.length; i++) {
topics[i] = topics[i].trim();
}
您只需使用ArrayList类附带的add方法。
ArrayList<String> tpc = new ArrayList<>();
for(int i = 0; i < topics.length; i++) {
topics[i] = topics[i].trim();
tpc.add(topics[i]);
}
这是一个如何将值插入数组列表的示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句