How to write the elements of the ArrayList?

Hi all. I'm starting to learn Java and have run into a problem. I have an ArrayList, how can I write elements with him, that they were discharged in square brackets as Arrays.toString(x)?
Right now I have issued this:
It should be:

And yet, I have on the 1st picture at the end of the last element with a comma. How to make so that it are not displayed??
Or just standing as it is to translate this ArrayList to a regular array? But how?
Thank you
July 2nd 19 at 13:54
2 answers
July 2nd 19 at 13:56
List List = new ArrayList();

 for(int i=0; i < 20; i++)

 //ArrayList to Array;
 Long[] mArray = new Long[list.size()];

 for(int i=0; i< mArray.length; i++)
 mArray[i] = (Long) list.get(i) ;

 System.out.println(list.size()+ "" + list.toString());
July 2nd 19 at 13:58
The best minds in the Java community over the years have struggled with this problem and if you do a little googling to find out what they came up with.

Find more questions by tags Java