Java printf functionality for collections or arrays

In python, you can use a tuple in a formatted print statement, and the tuple values ​​are used at the specified positions in the formatted string. For instance:

>>> a = (1,"Hello",7.2)
>>> print "these are the values %d, %s, %f" % a
these are the values 1, Hello, 7.200000

Is there a way to use any array or collection in a java printf expression in a similar way?

I looked at the documentation and it seems to have built-in support for some types, such as Calendar, but I do not see everything for collections.

If this is not indicated in java, is there any java java that will be used in that case when you fill collections and then print values ​​from many collections using one format string (other than a nested loop)

+3
source share
2

printf :

public PrintString printf(String format, Object... args);

... , []. ... . :

    out.printf("%s:%s", a, b);

:

    out.printf("%s:%s", new Object[] { a, b });

, , :

    out.printf("%s:%s", things);

:

    out.printf("%s:%s", things.toArray());
+12
+2

Source: https://habr.com/ru/post/1697629/


All Articles