java.util Code Samples
- How do I get date, month, year values from the current date?
- How do I convert an array into a collection object?
- How do I calculate difference in days between two dates?
- How do I add or subtract a date?
- How do I use StringTokenizer to split a string?
- How do I read file using Scanner class?
- How do I read user input from console using Scanner class?
- How do I sort items of an ArrayList?
- How do I convert array to Set?
- How do I get the current month name?
- How do I sort array values in descending order?
- How do I convert Set into List?
- How do I get the last day of a month?
- How do I convert milliseconds value to date?
How do I use ResourceBundle for i18n?
Creating an application for users in different regions can be hard in term of the message format for the local region. Java provide a ResourceBundle class that help internationalize our application.
To create resources for i18n (there are 18 letters between the first i and the final n) we need to create a file for each locale our application supported. The file name must be ended in language_COUNTRY.properties. For instance a resource bundle for Locale.UK will be MessagesBundle_en_GB.properties.
When the bundle has been loaded we can use bundle.getString(key) to read specific message from our resource bundle file.
Below are some example of our resource bundle files, these files should be located in our application classpath to enable the ResourceBundle class to read it.
MessagesBundle_en_GB.properties
greeting=Hello, how are you?
MessagesBundle_in_ID.properties
greeting=Halo, apa kabar?