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

后端 未结 11 2344
攒了一身酷
攒了一身酷 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:51

    The brackets you see are just an automatic way to display a List in JAVA (when using System.out.println(list); for example.

    If you do not want them to show when showing it, you can create a custom method :

    public void showList(List listInt)
    {
        for(int el : listInt)
        {
            System.out.print(el + ", ");
        }
    }
    

    Then adjust this code to show this according to your liking !

提交回复
热议问题