MessageFormat format Example

MessageFormat class format example. This example shows you how to use format method.


MessageFormat class format example.

Here is the code
/*
 * @ # Format.java
 * A class representing use to Format method 
 * of MessageFormat class in java.text package
 * version 17 June 2008
 * author Rose India 
 */

import java.text.*;
import java.util.*;

public class Format2 {

    public static void main(String args[]) {

        String pattern = "We are {0,number,#} boys and {1,number,#} girls";
        java.text.Format formats[] {new DecimalFormat()};
        //Format[] formats ={new DecimalFormat("#")};

        Object[] values = {new Integer(5)new Integer(10)};
        MessageFormat mFmt = new MessageFormat(pattern);
        mFmt.setFormats(formats);
        mFmt.applyPattern(pattern);
        System.out.println(mFmt.toPattern());
        System.out.println(mFmt.format(pattern, values));
    }
}

Output
We are {0,number,#} boys and {1,number,#} girls
We are 5 boys and 10 girls

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US