Java System.out.format with a double array

I am trying to infer information using System.out.format using the double [] array as an argument. This does not work:

out.format("New dimensions:\n" +
        "Length: %f\n" +
        "Width: %f\n\n",
        doubleArray);

This, however, does:

out.format("New dimensions:\n" +
        "Length: %f\n" +
        "Width: %f\n\n",
        doubleArray[0], doubleArray[1]);

Why does the first format not work? It supposedly works fine with strings.

+3
source share
2 answers

Java will avtoobektom doubleup double, but it will not be your car boxes double[]up double[], so it does not match Object[]. As a result, instead of unpacking in varargs, Object...your array is treated as the array itself, which obviously cannot be formatted as double.

If you declare your array as double[]instead double[], the call formatworks.

+4
source

, ( Java , ). , , - %f . ArraySomething [] ..

. Java - Java? Java.

+1

All Articles