Retrieving a format string from a Format object

In Java, there is a way to get a format string from a Format object (or any derived classes)

In code:

Format f = new DecimalFormat("$0.00");
System.out.println(???);

Is it possible to use System.out.println (???); printable "$ 0.00".

I looked at Pattern (); but this function is not displayed in the abstract Format class, and the variable I'm working with may be something that extends the format.

+3
source share
4 answers

The pattern (if one exists at all) depends on the subclass Format. There is no guarantee that I Formateven used a template to format it.

: , , Format, Serializable.

+1

, ! , , : - (

0

. Format (SimpleDateFormat, MessageFormat, ChoiceFormat, DecimalFormat); Pattern. , .

0

, , , , :

DecimalFormat f = new DecimalFormat("$0.00"); 
System.out.println(f.toPattern());
0

Source: https://habr.com/ru/post/1706340/


All Articles