Java Reference
In-Depth Information
Once a pattern has been applied to a SimpleDateFormat object, a long value
representing time can be passed to the SimpleDateFormat object's format()
method. The format() method will return the given date\time formatted using the
pattern that was applied. The string-based result can then be used however your applic-
ation requires.
4-18. Writing Readable Numeric Literals
Problem
Some of the numeric literals in your application are rather long and you want to make
it easier to tell how large a number is at a glance.
Solution
Use underscores in place of commas or decimals in larger numbers in order to make
them more readable. The following code shows some examples of making your numer-
ic literals more readable by using underscores in place of commas:
int million = 1_000_000;
int billion = 1_000_000_000;
float ten_pct = 1_0f;
double exp = 1_234_56.78_9e2;
How It Works
Sometimes working with large numbers can become cumbersome and difficult to read.
Because of the release of Java SE7, underscores can now be used with numeric literals
in order to make code a bit easier to read. The underscores can appear anywhere
between digits in a numeric literal. This allows for the use of underscores in place of
commas or spaces to separate the digits and make them easier to read.
Search WWH ::




Custom Search