How to convert an array to string in java?

Java 8Object Oriented ProgrammingProgramming

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]
raja
Published on 09-Jan-2018 08:09:51
Advertisements