Class Formatter


  • public final class Formatter
    extends Object
    Formats a string with the contents of one or more objects.

    If possible, uses each object's toString method. If this throws an exception, Formatter creates its own string representation of the object, containing its class name and the contents of its fields.

    • Method Detail

      • of

        public static Formatter of​(String message,
                                   Object... objects)
        Factory method.
        Parameters:
        message - The string that will be formatted. The substring %% represents the location where each object's will string representation will be inserted.
        objects - The objects whose string representation will be inserted into the message string.
        Returns:
        A Formatter.
      • format

        public String format()
        Formats the message with the given objects.
        Returns:
        The message, with the given objects's string representations inserted into it.
        Throws:
        IllegalStateException - if the number of %%'s in the message does not match the number of objects.