Output ArrayList to String without [,] (brackets) appearing

后端 未结 10 1261
你的背包
你的背包 2020-12-17 10:30

OK, so I have an ArrayList that I need to return as a String. Right now I am using this approach:

List customers = new ArrayList<>();
L         


        
10条回答
  •  情话喂你
    2020-12-17 11:25

    If you want your output to look like: item1, item2, item3

    Arrays.toString(customers.toArray()).replace('[', ' ').replace(']', ' ').trim()
    

    If you want your output to look like: item1 item2 item3

    Arrays.toString(customers.toArray()).replace('[', ' ').replace(']', ' ').replace(',', ' ').trim()
    

提交回复
热议问题