英文:
How do i display the Array List without [], and next lines instead of displaying on [1,2,3]
问题
这是我的代码
private List[] split(ArrayList aList) {
ArrayList first = new ArrayList();
ArrayList second = new ArrayList();
int size = aList.size();
for (int i = 0; i < size / 2; i++)
first.add(aList.get(i));
for (int i = size / 2; i < size; i++)
second.add(aList.get(i));
return new List[] { first, second };
}
Collections.shuffle(list);
List[] lists = split(list);
jTextArea2.append(lists[0].toString());
jTextArea3.append(lists[1].toString());
现在的显示如下... 我希望在“上传的列表”中显示在 Team A 和 Team B 中的列表
英文:
Here is my code
private List[] split(ArrayList aList) {
ArrayList first = new ArrayList();
ArrayList second = new ArrayList();
int size = aList.size();
for (int i = 0; i < size / 2; i++)
first.add(aList.get(i));
for (int i = size / 2; i < size; i++)
second.add(aList.get(i));
return new List[] { first, second };
}
Collections.shuffle(list);
List[] lists = split(list);
jTextArea2.append(lists[0].toString());
jTextArea3.append(lists[1].toString());
This is how it looks like now... i want the list in Team A and Team B to be displayed list in Uploaded list
答案1
得分: 2
逐个添加每个元素:
for (int i = 0; i < lists[0].size(); i++) {
jTextArea2.append(lists[0].get(i).toString());
jTextArea2.append("\n");
}
英文:
Add each element separately:
for (int i = 0; i < lists[0].size(); i++) {
jTextArea2.append(lists[0].get(i).toString());
jTextArea2.append("\n");
}
答案2
得分: 0
你可以使用来自Streams API的joining collector。
jTextArea2.append(lists[0].stream()
.map(Object::toString)
.collect(Collectors.joining("\n")));
英文:
You can use joining collector from Streams api.
jTextArea2.append(lists[0].stream()
.map(Object::toString)
.collect(Collectors.joining("\n")));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论