import java.text.MessageFormat; import java.util.Date; public class MessageFormatTest { public static void main(String args[]){ Object[] params = new Object[] { "hello", "!" }; System.out.println(MessageFormat.format("{0} world {1}", params)); Object[] params1 = new Object[] { new Integer(123), new Integer(1234) }; String msg = MessageFormat.format("{0} a''s and {1} b''s", params1); System.out.println(msg); Object[] params2 = new Object[] { new Integer(123), new Integer(1234) }; String msg1 = MessageFormat.format("{0,number} a''s and {1,number} b''s", params2); System.out.println(msg1); Object[] params3 = new Object[] { new Double(123.45), new Double(1234.56) }; String msg2 = MessageFormat.format("{0,number,#.#} a''s and {1,number,#.#} b''s", params3); System.out.println(msg2); Object[] params4 = new Object[] { new Double(123.45), new Double(1234.56) }; String msg3 = MessageFormat.format("{0,number,currency} a''s and {1,number,currency} b''s", params4); System.out.println(msg3); Object[] params5 = new Object[] { new Double(123.45), new Double(1234.56) }; String msg4 = MessageFormat .format("{0,number,percent} a''s and {1,number,percent} b''s", params5); System.out.println(msg4); Object[] params6 = new Object[] { new Date(), new Date(0) }; String msg5 = MessageFormat.format("The time is {0} and UTC of 0 is {1}", params6); msg5 = MessageFormat.format("The time is {0,time} and UTC of 0 is {1,time}", params6); System.out.println(msg5); Object[] params7 = new Object[] { new Date(), new Date(0) }; String msg6 = MessageFormat.format("{0,time,short} and UTC of 0 is {1,time,short}", params7); System.out.println(msg6); Object[] params8 = new Object[] { new Date(), new Date(0) }; String msg7 = MessageFormat.format("{0,time,medium} and UTC of 0 is {1,time,medium}", params8); System.out.println(msg7); Object[] params9 = new Object[] { new Date(), new Date(0) }; String msg8 = MessageFormat.format("{0,time,long} and UTC of 0 is {1,time,long}", params9); System.out.println(msg8); Object[] params10 = new Object[] { new Date(), new Date(0) }; String msg9 = MessageFormat.format("{0,time,full} and UTC of 0 is {1,time,full}", params10); System.out.println(msg9); Object[] params11 = new Object[] { new Date(), new Date(0) }; String msg10 = MessageFormat .format("{0,time,HH-mm-ss} and UTC of 0 is {1,time,HH-mm-ss}", params11); System.out.println(msg10); Object[] params12 = new Object[] { new Date(), new Date(0) }; String msg11 = MessageFormat.format("Today is {0} and UTC of 0 is {1}", params12); System.out.println(msg11); Object[] params13 = new Object[] { new Date(), new Date(0) }; String msg12 = MessageFormat.format("Today is {0,date} and UTC of 0 is {1,date}", params13); System.out.println(msg12); Object[] params14 = new Object[] { new Date(), new Date(0) }; String msg13 = MessageFormat.format("Today is {0,date,short} and UTC of 0 is {1,date,short}", params13); System.out.println(msg13); Object[] params15 = new Object[] { new Date(), new Date(0) }; String msg14 = MessageFormat.format("Today is {0,date,medium} and UTC of 0 is {1,date,medium}", params15); System.out.println(msg14); Object[] params16 = new Object[] { new Date(), new Date(0) }; String msg15 = MessageFormat.format("Today is {0,date,long} and UTC of 0 is {1,date,long}", params16); System.out.println(msg15); Object[] params17 = new Object[] { new Date(), new Date(0) }; String msg16 = MessageFormat.format("Today is {0,date,long} and UTC of 0 is {1,date,long}", params17); System.out.println(msg16); } }