How do i display the Array List without [], and next lines instead of displaying on [1,2,3]

huangapple go评论67阅读模式
英文:

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 中的列表

How do i display the Array List without [], and next lines instead of displaying on [1,2,3]

英文:

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 &lt; size / 2; i++) 
             first.add(aList.get(i));
    
    for (int i = size / 2; i &lt; 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

How do i display the Array List without [], and next lines instead of displaying on [1,2,3]

答案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 &lt; lists[0].size(); i++) {
    jTextArea2.append(lists[0].get(i).toString());
    jTextArea2.append(&quot;\n&quot;);
} 

答案2

得分: 0

你可以使用来自Streams APIjoining 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(&quot;\n&quot;)));

huangapple
  • 本文由 发表于 2020年5月3日 20:36:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/61574531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定