varargs question

I have the following code:

	public static String dumpHex(byte... hex) {
		String format = "$";

		for (int i = 0; i < hex.length; i++) {
			format += "%02X ";
		}
		return String.format(format,hex);
	}

My methods takes varargs and String.format too. But this gives me a IllegalFormatConversionException. How do I solve this ?

I don’t know about formatting but the Javadoc point to this for more details :slight_smile:

String.format expects an Object[] where each entry corresponds to one argument you want to format.
You could try this:

...
Object[] tmp = new Object[hex.length];
for(int i=0 ; i<hex.length ; i++) {
   tmp[i] = Integer.valueOf(hex[i] & 255);
}
return String.format(format, tmp);