Java Reference
In-Depth Information
Using this notation, instead of directly typing the character using your keyboard, you
enter \u or \U , followed by the hexadecimal representation of the Unicode code point.
This recipe's code sample uses the Japanese word “ ” (pronounced mo-ji ). As
the example shows, you can use the actual characters in the regular expression or you
can look up the Unicode code point values. For this particular Japanese word, the en-
coding will be \u6587\u5B57 .
The Java language's regular expression support includes special character classes.
For example, \d and \w are shortcut notations for the regular expressions [0-9] and
[a-zA-Z_0-9] , respectively. However, because of the Java compiler's special hand-
ling of the backslash character, you must use an extra backslash when using predefined
character classes such as \d (digits), \w (word characters), and \s (space characters).
To use them in source code, for example, you enter \\d , \\w , and \\s , respectively. The
sample code used the double backslash in Solution 1 to represent the \w character
class:
String enRegEx = "^The \\w + cat.*";
12-6. Overriding the Default Currency
Problem
You want to display a number value using a currency that is not associated with the de-
fault locale.
Solution
Take control of which currency is printed with a formatted currency value by explicitly
setting the currency used in a NumberFormat instance. The following example as-
sumes that the default locale is Locale.JAPAN . It changes the currency by calling
the setCurrency(Currency c) method of its NumberFormat instance. This
example comes from the
org.java8recipes.chapter12.recipe12_5.Recipe12_5 class.
BigDecimal value = new BigDecimal(12345);
System.out.printf("Default locale: %s\n",
Search WWH ::




Custom Search