MessageFormat clone Example

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


MessageFormat class clone example. public Object clone() Creates and returns a copy of this object.

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

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

public class Clone {

    public static void main(String[] args) {
        
        String pattern = "I bought {0,number,#} apple";

        java.text.Format formats[] {new DecimalFormat()};
        //Format[] formats ={new DecimalFormat("#")};

        Object[] values = {new Integer(500)};

        MessageFormat mFmt = new MessageFormat(pattern);

        mFmt.setFormats(formats);
        mFmt.applyPattern(pattern);

        //Create clone
        MessageFormat mFmt1 = (MessageFormatmFmt.clone();

        System.out.println(mFmt1.toPattern());
        System.out.println(mFmt1.format(values));
    }
}

Output
I bought {0,number,#} apple
I bought 500 apple

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

HOME | COPYRIGHT | CONTACT US