Mega Code Archive

 
Categories / Java by API / Java Text
 

New MessageFormat(String pattern)

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 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);   } }