Retrieve version from maven pom.xml in java

Today we will discuss working with pom.xml. Suppose you have a web application and you want to print its current version in some part of the page.
Of course you can save the version in a separate parameter and read from there. But there is an option better. We can determine the version by reading it directly from pom.xml.

Continue reading “Retrieve version from maven pom.xml in java”

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”