MessageFormatApp.java Source code

Java tutorial

Introduction

Here is the source code for MessageFormatApp.java

Source

import java.text.MessageFormat;
import java.util.Date;

class MessageFormatApp {
    public static void main(String args[]) {
        String pattern = "The time is {0,time} and ";
        pattern += "your lucky number is {1,number}.";
        MessageFormat format = new MessageFormat(pattern);
        Object objects[] = { new Date(), new Integer((int) (Math.random() * 1000)) };
        String formattedOutput = format.format(objects);
        System.out.println(formattedOutput);
    }
}