Java Collection How to - Convert array to String for one dimensional and multi-dimensional arrays








Question

We would like to know how to convert array to String for one dimensional and multi-dimensional arrays.

Answer

// w ww .j av a2 s .co m
import java.util.Arrays;

public class Main {
  public static void main(String args[]) {
    String s[] = {"a", "b", "c", "d"};
    double d [][]= {
        {0.50, 0.20,  0.20, 0.30},
        {0.50, 1.10,  0.50, 0.80},
        {0.50, 0.70,  0.40},
        {0.50, 0.70},
        {0.50},
    };
    System.out.println(Arrays.toString(s));
    System.out.println(Arrays.deepToString(d));
  }
}

The code above generates the following result.