The exception asks you for an array instead comma-sepparated strings:

// incorrect
String.format("%02d:%02d:%02d",hour,minute,second);

// fast but correct
Object[] data = { hour, minute, second };
String.format("%02d:%02d:%02d", data);

But actually, method format(String,object[]) does not exists in String, it is: format(String pattern, Object... arguments) what should work with commas ,. There is something with your syntax, but not in the shown code.

Answer from Jordi Castilla on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › java string.format()
Java String.format() | Baeldung
4 days ago - This enables reordering or reusing arguments within the format string without changing their order in the argument list. To apply a locale other than the default locale, we can use the method version that specifies Locale as the first argument. Format specifiers have their own syntax, which varies depending on the type of argument they apply to.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Formatter.html
Formatter (Java Platform SE 8 )
2 weeks ago - Java™ Platform Standard Ed. 8 ... An interpreter for printf-style format strings. This class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output. Common Java types such as byte, BigDecimal, and Calendar ...
🌐
Javatpoint
javatpoint.com › java-string-format
Java String format()
Java String format() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string format in java etc.
🌐
Baeldung
baeldung.com › home › java › java string › guide to java.util.formatter
Guide to java.util.Formatter | Baeldung
January 8, 2024 - In this article, we’ll discuss the String formatting in Java using the java.util.Formatter class, which provides support for the layout justification and alignment.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
2 weeks ago - args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java™ Virtual Machine Specification.
🌐
W3Schools
w3schools.com › java › ref_string_format.asp
Java String format() Method
Strings Concatenation Numbers and Strings Special Characters Code Challenge Java Math Java Booleans
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-format-method-with-examples
Java String format() Method - GeeksforGeeks
July 11, 2025 - // Java program to demonstrate // complex placeholder formatting class Geeks { public static void main(String args[]) { // Declare a double value // representing the distance double d = 1500.75; // Declare a string value // representing the unit of measurement String s = "kilometers"; // Correct the argument order to match the format specifiers String res = String.format("%1$,7.1f %2$s", d, s); System.out.println(res); } } Output · 1,500.8 kilometers ·
Find elsewhere
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › use-string-format-java-string-output
Java String formatting with the String.format method (like ‘sprintf’) | alvinalexander.com
July 30, 2024 - The %d symbol is a placeholder that indicates that a decimal value (something like an int or long in Java) should be printed in place of this symbol. The value of that decimal comes from the variable that follows my string, in this case the RENAME_SUCCEEDED variable. If it helps to see the format method used without the additional log.debug method, here’s an example where I use the String.format method to assign a similarly formatted String to another String:
🌐
Mkyong
mkyong.com › home › java › java string format examples
Java String Format Examples - Mkyong.com
March 10, 2020 - Further Reading- Formatter JavaDoc. ... package com.mkyong; public class JavaStringFormat1 { public static void main(String[] args) { String result = String.format("%s is %d", "mkyong", 38); // mkyong is 38 System.out.println(result); String result2 = String.format("%d + %d = %d", 1, 1, 1 + 1); // 1 + 1 = 2 System.out.println(result2); String result3 = String.format("%s = %f", "PI", Math.PI); // PI = 3.141593 String result4 = String.format("%s = %.3f", "PI", Math.PI); // PI = 3.142 System.out.println(result3); System.out.println(result4); } }
🌐
DZone
dzone.com › data engineering › data › java string format examples
Java String Format Examples: 2021 Edition
July 11, 2021 - If there were a “java sprintf” then this would be it. String output = String.format("%s = %d", "joe", 35);
🌐
DZone
dzone.com › coding › java › formatting strings in java: string.format() method
Formatting Strings in Java: String.format() Method
November 13, 2024 - Core Java Specialization | Enroll in Free Online Course Today* ... There are three primary ways to format a string in Java. You can use the String.format() method, the printf() method, or the MessageFormat class for formatting strings.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › Format.html
Format (Java Platform SE 8 )
2 weeks ago - Generally, a format's parseObject method must be able to parse any string formatted by its format method. However, there may be exceptional cases where this is not possible. For example, a format method might create two adjacent integer numbers with no separator in between, and in this case the parseObject could not tell which digits belong to which number. The Java Platform provides three specialized subclasses of Format-- DateFormat, MessageFormat, and NumberFormat--for formatting dates, messages, and numbers, respectively.
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-string-format-method
Java String format() method
June 9, 2024 - public class Example{ public static void main(String args[]){ String name = "Chaitanya"; int age = 37; double luckyNum = 123.456; String formattedString = String.format("Name: %s, Age: %d, Lucky No: $%.2f", name, age, luckyNum); System.out.println(formattedString); // Output: Name: Chaitanya, Age: 37, Lucky No: $123.456 } } import java.util.Date; public class Example{ public static void main(String args[]){ Date date = new Date(); String formattedDate = String.format("Current DateTime: %tc", date); System.out.println(formattedDate); // Output: Current DateTime: Sat Jun 08 07:39:52 PDT 2024 } }
🌐
Medium
medium.com › kwal-it › how-to-format-a-string-in-java-950d07ea8be6
How To Format A String in Java. Formatted is the new kid in town | by Dieter Jordens | Kwal-IT | Medium
May 2, 2024 - You will see the latest and the fastest way of formatting a string for Java 17. ... Since Java 15, you can now format a String with a new method, formatted. This method is the same as the well know static String format method.
🌐
Kansas State University
textbooks.cs.ksu.edu › cc210 › 09-strings › 06-java › 04-formatting
String Formatting :: CC 210 Textbook
June 27, 2024 - In addition, many of the placeholders can also specify the width and precision of each output. Here’s an updated example using these formatting options: int sum = 123; double avg = 1.23; String name = "Student"; String output = "%s: Your score is ] with an average of %8.4f."; System.out.println(String.format(output, name, sum, avg));
🌐
Jmu
wiki.cs.jmu.edu › reference › java › formatting
Formatting Strings and Output in Java - JMU CS Wiki
January 26, 2026 - The optional width determines the total number of characters that this portion of the String will contain. The optional precision determines the nnumbenr of digits to the right of the decimal point for double values. So, for example the format specifier � indicates an int that will be right-justified in a field of width 8.
🌐
Programiz
programiz.com › java-programming › library › string › format
Java String format()
Similarly, %x is replaced with the hexadecimal value of number in String.format("Number: %x", number). ... class Main { public static void main(String[] args) { int n1 = 47; float n2 = 35.864f; double n3 = 44534345.76d; // format as an octal number
🌐
Stack Abuse
stackabuse.com › how-to-format-a-string-in-java-with-examples
Format String in Java with printf(), format(), Formatter and MessageFormat
October 22, 2021 - Finally, all format specifiers, escape characters, etc. are also valid for the Formatter class as this is the main logic for formatting Strings in all three cases: String.format(), printf(), and Formatter. Finally, let's show one final formatting technique that doesn't use Formatter under the hood. MessageFormat was made to produce and provide concatenated messages in a language-neutral way. This means that the formatting will be the same, regardless of whether you're using Java, Python, or some other language that supports MessageFormat.
🌐
Educative
educative.io › answers › what-is-the-stringformat-method-in-java
What is the String.format() method in Java?
The Java String.format() method returns the formatted string by a given locale, format, and argument.