How about making your item array of type Object[], and then simply pass that as the second parameter, rather than passing each of the array items individually?

SCJP 5, SCWCD 5

Campbell Ritchie

Marshal

Posts: 56546

172

posted 2 years ago

Do you mean you have an array which needs to be printed out?

You can set up a loop to add the same number of %cs as there are elements in the array. But there are bound to be more object‑oriented ways to do it.
You can use Arrays#toString.
You can create a Stream from some arrays (won't work in Java7):-
Arrays.stream(myCharArray).forEach(c -> System.out.printf("%c ", c));
System.out.println(); That might not work with a char[]; look in the Arrays class.

And other people will doubtless be able to think of other solutions.

Campbell Ritchie

Marshal

Posts: 56546

172

posted 2 years ago

You can use a StringJoiner for each element in an array. You can turn the array into a String and remove characters like comma and square bracket.