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]