This post will discuss how to convert primitive integer array to string array in Java.

1. Naive solution

A naive solution is to create an array of string type and use a regular for-loop to assign values to it from a primitive integer array after converting int to strings.

Download  Run Code

Output:

[1, 2, 3, 4, 5]

2. Using Java 8

Another solution is to use Java 8 Stream to convert a primitive integer array to string array:

  1. Convert the specified primitive array to a IntStream using Arrays.stream() or IntStream.of() method.
  2. Convert each element of the stream to a string using IntStream.mapToObj() method.
  3. Return a string array containing elements of this stream using Stream.toArray().

The following program demonstrates it:

Download  Run Code

Output:

[1, 2, 3, 4, 5]

3. Using Regex

This approach is not recommended.

Download  Run Code

Output:

[1, 2, 3, 4, 5]

That’s all about converting int array to string array in Java.