About Question enthuware.ocpjp.v11.2.1432 :
Posted: Thu Sep 29, 2022 2:16 am
The option 2, is misguiding,
You can set the Locale after constructing a DateFormat or a NumberFormat object and before using it to do country specific formatting.
we can actually, set the default local, calling, Locale.setDefault(Locale.US)
1. NumberFormat f = NumberFormat.getInstance();
2. Locale.setDefault(Locale.Category.FORMAT,Locale.US)
3. f.format(23456.56);
The first line formatter, will be always impacted by the line 2,
NumberFormat f = NumberFormat.getInstance(Locale.US);, this shall not get impacted by, the second line.
EDIT:
Hi, I tried the thing, it does not seem, to work,
The instance returned, in the 1st line does not seem to get impacted, by the second line.
You can set the Locale after constructing a DateFormat or a NumberFormat object and before using it to do country specific formatting.
we can actually, set the default local, calling, Locale.setDefault(Locale.US)
1. NumberFormat f = NumberFormat.getInstance();
2. Locale.setDefault(Locale.Category.FORMAT,Locale.US)
3. f.format(23456.56);
The first line formatter, will be always impacted by the line 2,
NumberFormat f = NumberFormat.getInstance(Locale.US);, this shall not get impacted by, the second line.
EDIT:
Hi, I tried the thing, it does not seem, to work,
The instance returned, in the 1st line does not seem to get impacted, by the second line.