Java: Printing out all the integers in args array

syncoroll picture syncoroll · Aug 10, 2011 · Viewed 18.5k times · Source

How do I print out a set of integers from my args variable in Java?

I tried:

System.out.println("The numbers are " + args.length);

But all that does is print out the number of elements in the array.

I want it so that if there are 5 arguments passed: 1 2 3 4 5 the output should be:

1, 2, 3, 4, 5

Answer

Thilo picture Thilo · Aug 10, 2011

Take a look if you like

  System.out.println("The numbers are "+Arrays.toString(args));

If not, you'll have to loop over the array and format it yourself.