简体   繁体   English

防止jTextArea添加[追加arraylist时

[英]Prevent jTextArea from adding [ when appending arraylist

I have a JTextArea that appends an ArrayList<String> . 我有一个JTextArea追加ArrayList<String> This works well enough. 这足够好用。 But its also adding [ characters in as well. 但它也添加了[字符。 How can I prevent this? 我该如何预防?

jTextArea1.append(myarraylist.toString() + COMMA_DELIMITER + "\n");

You can't append the toString() of an ArrayList, unless you like the exact formatting of the toString() method of the ArrayList. 除非您喜欢ArrayList的toString()方法的确切格式,否则您不能追加ArrayList的toString()。

If you want custom formatting of the data you need to add each element separately by iterating through each element in the ArrayList. 如果要自定义数据格式,则需要通过迭代ArrayList中的每个元素来分别添加每个元素。 Something like: 就像是:

for (Object text: myArrayList)
{
    jTextArea1.append(text.toString() + "...");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM