Changes to java.text.MessageFormat in JDK1.5

Before the new 1.5 feature that allows for a variable number of arguments in methods, the class MessageFormat could only be using an array of Objects as shown in the following example

Main.java:

import java.text.MessageFormat;
import java.util.Date;
 
public class Main
{
   public static void main(String args[]) throws Exception
   {
      Object[] arguments = {"John", new Date()};
      
      String template = "{0}, the date is {1,time,short}";
      String message = MessageFormat.format(template, arguments);
 
      System.out.println(message);
   }
}

With 1.5, there is a new overloaded format method declared as follows:

   public static String format(String pattern, Object... arguments)

This allows you to rewrite the above code as follows:

import java.text.MessageFormat;
import java.util.Date;
 
public class Main
{
   public static void main(String args[]) throws Exception
   {
      String template = "{0}, the date is {1,time,short}";
      String message = MessageFormat.format(template, "John", new Date());
 
      System.out.println(message);
   }
}