diff --git a/src/java.base/share/classes/java/text/MessageFormat.java b/src/java.base/share/classes/java/text/MessageFormat.java index 2e842763258..792fce2e811 100644 --- a/src/java.base/share/classes/java/text/MessageFormat.java +++ b/src/java.base/share/classes/java/text/MessageFormat.java @@ -230,14 +230,16 @@ import java.util.Locale; *

* The first example uses the static method {@code MessageFormat.format}, * which internally creates a {@code MessageFormat} for one-time use: - *

+ * 
+ * {@snippet lang=java : * int planet = 7; * String event = "a disturbance in the Force"; * * String result = MessageFormat.format( * "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", * planet, new Date(), event); - *
+ * } + * * The output is: *
  * At 12:30 PM on Jul 3, 2053, there was a disturbance in the Force on planet 7.
@@ -246,7 +248,8 @@ import java.util.Locale;
  * 

* The following example creates a {@code MessageFormat} instance that * can be used repeatedly: - *

+ * 
+ * {@snippet lang=java : * int fileCount = 1273; * String diskName = "MyDisk"; * Object[] testArgs = {Long.valueOf(fileCount), diskName}; @@ -255,7 +258,8 @@ import java.util.Locale; * "The disk \"{1}\" contains {0} file(s)."); * * System.out.println(form.format(testArgs)); - *
+ * } + *
* The output with different values for {@code fileCount}: *
  * The disk "MyDisk" contains 0 file(s).
@@ -266,7 +270,8 @@ import java.util.Locale;
  * 

* For more sophisticated patterns, you can use a {@code ChoiceFormat} * to produce correct forms for singular and plural: - *

+ * 
+ * {@snippet lang=java : * MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}."); * double[] filelimits = {0,1,2}; * String[] filepart = {"no files","one file","{0,number} files"}; @@ -278,7 +283,8 @@ import java.util.Locale; * Object[] testArgs = {Long.valueOf(fileCount), diskName}; * * System.out.println(form.format(testArgs)); - *
+ * } + *
* The output with different values for {@code fileCount}: *
  * The disk "MyDisk" contains no files.
@@ -290,10 +296,12 @@ import java.util.Locale;
  * You can create the {@code ChoiceFormat} programmatically, as in the
  * above example, or by using a pattern. See {@link ChoiceFormat}
  * for more information.
- * 
{@code
+ * 
+ * {@snippet lang=java : * form.applyPattern( * "There {0,choice,0#are no files|1#is one file|1
+ * } + *
* *

* Note: As we see above, the string produced @@ -305,25 +313,29 @@ import java.util.Locale; *

* When a single argument is parsed more than once in the string, the last match * will be the final result of the parsing. For example, - *

+ * 
+ * {@snippet lang=java : * MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}"); * Object[] objs = {Double.valueOf(3.1415)}; * String result = mf.format( objs ); * // result now equals "3.14, 3.1" * objs = mf.parse(result, new ParsePosition(0)); * // objs now equals {Double.valueOf(3.1)} - *
+ * } + *
* *

* Likewise, parsing with a {@code MessageFormat} object using patterns containing * multiple occurrences of the same argument would return the last match. For * example, - *

+ * 
+ * {@snippet lang=java : * MessageFormat mf = new MessageFormat("{0}, {0}, {0}"); * String forParsing = "x, y, z"; * Object[] objs = mf.parse(forParsing, new ParsePosition(0)); * // result now equals {new String("z")} - *
+ * } + * * *

Synchronization

*