Convert array to string

ReturnMethodSummary
static StringtoString(boolean[] a)Returns a string representation of the contents of the specified array.
static StringtoString(byte[] a)Returns a string representation of the contents of the specified array.
static StringtoString(char[] a)Returns a string representation of the contents of the specified array.
static StringtoString(double[] a)Returns a string representation of the contents of the specified array.
static StringtoString(float[] a)Returns a string representation of the contents of the specified array.
static StringtoString(int[] a)Returns a string representation of the contents of the specified array.
static StringtoString(long[] a)Returns a string representation of the contents of the specified array.
static StringtoString(Object[] a)Returns a string representation of the contents of the specified array.
static StringtoString(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]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.