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

后端 未结 10 1243
你的背包
你的背包 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

    I think the best solution to print list without brackets and without any separator( for java 8 and higher )

    String.join("", YOUR_LIST);
    

    You can alos you you own delimiter to separate printing elements.

    String.join(", \n", YOUR_LIST);
    

    example above separate each list element with comma and new line.

提交回复
热议问题