How to generate a MS Word document (docx) from Java

In today’s article, we’ll look at generating a document based on the docx document template. This is a very common task in business applications where you service needs to provide a report to a user based on his actions.
To generate the that document, we will use the docx-stamper library.

Continue reading “How to generate a MS Word document (docx) from Java”

How to convert java string array to string with delimiter

Using String.join method (from java 8)

Using simple for-loop expression

 

How to convert an int to a formatted string in java

Using java.util.formatter

See the Formatter docs for other modifiers.

2 code examples to convert int[] to Integer[]

Convert using java streams (from java 8)

Using regular for-loop without external libraries:

Using Guava library

 

4 code examples to check If a String is an Integer in Java

Suppose we have the following problem. User input some value, how to check that this value is a String is an integer:

1. Check by Exception

Continue reading “4 code examples to check If a String is an Integer in Java”

Output data to excel file by template with jxls

Let’s assume we have a Java collection of Car objects that we want to output into Excel. The Car class may look like this

To use Jxls to output this object collection into an Excel we need to do the following

Continue reading “Output data to excel file by template with jxls”