How to remove the brackets [ ] from ArrayList#toString()?

后端 未结 11 2457
攒了一身酷
攒了一身酷 2021-01-03 14:09

I have created an Array List in Java that looks something like this:

 public static ArrayList error = new ArrayList<>();

for (int x= 1         


        
11条回答
  •  醉酒成梦
    2021-01-03 14:57

    The brackets are not actually within the list it's just a representation of the list. If any object goes into a String output the objects toString() method gets called. In case of ArrayList this method delivers the content of the list wrapped by this brackets.

    If you want to print your ArrayList without brackets just iterate over it and print it.

提交回复
热议问题