Writing forEach with java 8 lambda

Let’s take a simple example. It’s easier, probably, and can not be – create a list of numbers and display it on the screen through the simplest cycle:

Continue reading “Writing forEach with java 8 lambda”

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 (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”