Code example for MessageFormat

0
    } 
 
    public void t_format_with_FieldPosition() { 
 
        String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
        MessageFormat format = new MessageFormat(pattern, Locale.US);
 
        Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
        Integer hamburgers = new Integer(8);
        Object[] objects = new Object[] { hamburgers, new Double(3.5),
                hamburgers, date, date };
 
        super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!"; 
 
        // test with MessageFormat.Field.ARGUMENT 
        t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
 
        // test other format fields that are included in the formatted text 
        t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0,
                0); 
        t_FormatWithField(3, format, objects, null,
                NumberFormat.Field.FRACTION, 0, 0);
 
        // test fields that are not included in the formatted text 
        t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
        t_FormatWithField(5, format, objects, null,
                NumberFormat.Field.EXPONENT_SIGN, 0, 0);
    } 
 
    public void t_formatToCharacterIterator() {