Home » Core Java » text

text

Java MessageFormat Example

In this example we will discuss about MessageFormat class and how to use it to write messages. MessageFormat takes a set of objects, formats them, then inserts the formatted strings into the pattern at the appropriate places. MessageFormat extends the Format class, which is an abstract base class for formatting locale-sensitive information such as dates, messages, and numbers. It defines ...

Read More »

Java Decimal Format Example

In this example we will see how we can use the DecimalFormatclass to format decimal numbers. This class is useful when we want to format the decimal numbers in following ways : As per a defined specific string pattern We can specify a pattern string to define the display of the decimal. Specific to a locale We can use locale-specific settings ...

Read More »

Java SimpleDateFormat Example

In this example we will show how to use java.text.SimpleDateFormat class so as to convert a Date into a formatted string or a string to a Date. You can make this conversion using the constructors provided by java.text.SimpleDateFormat class and some patterns, such as dd/MM/yyyy, dd-MM-yy and so on, so as to format the Date as you wish. We will ...

Read More »

Java SimpleDateFormat and DateFormat Example

In this example we will show how to use java.text.SimpleDateFormat class so as to format date into text or parse text into date. SimpleDateFormat extends the java.text.DateFormat class which is an abstract class for date/time formatting subclasses and provides many class methods for obtaining default date/time formatters based on any given locale. We will see the usage of the class ...

Read More »

Java number format Example

There are many situations that we want to have a specific format in some numbers of our java applications. Depending on the format of the number, this may be done with different ways. Generally for a more well-written code and a more dynamic way, it is recommended the use of DecimalFormat class. This class give us the manner of formatting ...

Read More »

Format number with custom NumberFormat

In this example we shall show you how to format a number with a custom NumberFormat. NumberFormat provides the interface for formatting and parsing numbers. It also provides methods for determining which locales have number formats, and what their names are. To format a number with custom NumberFormat one should perform the following steps: Create a new DecimalFormat, using a ...

Read More »

Parse custom formatted date with SimpleDateFormat

With this example we are going to demonstrate how to parse custom formatted date with SimpleDateFormat. SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows formatting (date -> text), parsing (text -> date), and normalization. In short, to parse custom formatted date with SimpleDateFormat you should: Create a new SimpleDateFormat, using a String ...

Read More »

Format date in custom formats with SimpleDateFormat

This is an example of how to format a Date in custom formats, with the SimpleDateFormat. SimpleDateFormat can be used to format and parse dates. Formating a Date in custom format with the SimpleDateFormat implies that you should: Create a new Date. Create a new SimpleDateFormat, using a String pattern. The pattern describes the date and time format. Invoke the ...

Read More »

Convert dates between formats with SimpleDateFormat

In this example we shall show you how to convert dates between formats with SimpleDateFormat. To convert dates between formats with SimpleDateFormat one should perform the following steps: Create a new String to be used as the date that will be parsed by the SimpleDateFormat. Create a new SimpleDateFormat, using a String pattern to describe the date and time format. ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns