How to convert an array to string in java?


The Arrays class of the java.util package provides toString() methods for all primitive data types and object. These methods accept an array and return its string representation.

Therefore, to convert an array to string pass the required array to this method.

Example

Live Demo

import java.util.Arrays;

public class ArrayToString {
   public static void main(String args[]) throws Exception {
      int[] myArray = {23, 93, 56, 92, 39};
      String str = Arrays.toString(myArray);
      System.out.println(str);
   }
}

Output

[23, 93, 56, 92, 39]

Updated on: 16-Jun-2020

628 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements