Convert array to string

static String toString(boolean[] a)
Returns a string representation of the contents of the specified array.
static String toString(byte[] a)
Returns a string representation of the contents of the specified array.
static String toString(char[] a)
Returns a string representation of the contents of the specified array.
static String toString(double[] a)
Returns a string representation of the contents of the specified array.
static String toString(float[] a)
Returns a string representation of the contents of the specified array.
static String toString(int[] a)
Returns a string representation of the contents of the specified array.
static String toString(long[] a)
Returns a string representation of the contents of the specified array.
static String toString(Object[] a)
Returns a string representation of the contents of the specified array.
static String toString(short[] a)
Returns a string representation of the contents of the specified array.

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    byte[] b1 = new byte[] { 3, 2, 5, 4, 1 };
    System.out.println(Arrays.toString(b1));

    Arrays.sort(b1);
    System.out.println(Arrays.toString(b1));
    

    byte[] b2 = new byte[] { 5, 2, 3, 1, 4 };
    Arrays.sort(b2, 1, 4);

    System.out.println(Arrays.toString(b2));
  }

}

The output:


[3, 2, 5, 4, 1]
[1, 2, 3, 4, 5]
[5, 1, 2, 3, 4]
Home 
  Java Book 
    Collection  

Arrays:
  1. Arrays
  2. Convert array to list
  3. Binary search an Array
  4. Deep to string
  5. Compare two arrays
  6. Fill value to array
  7. Sort an array
  8. Convert array to string