Example usage for java.util Arrays toString

List of usage examples for java.util Arrays toString

Introduction

In this page you can find the example usage for java.util Arrays toString.

Prototype

public static String toString(Object[] a) 

Source Link

Document

Returns a string representation of the contents of the specified array.

Usage

From source file:Main.java

public static void main(String[] args) {

    // initializing int array
    int arr[] = new int[] { 1, 2, 3, 4, 5 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 18 from index 2 to 4
    Arrays.fill(arr, 2, 4, 18);// ww  w .  ja  v  a2  s  .  c  o  m

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

From source file:Main.java

public static void main(String[] args) {

    // initializing unsorted byte array
    byte bArr[] = { 10, 12, 7, 35 };

    System.out.println(Arrays.toString(bArr));

    // sorting array
    Arrays.sort(bArr);/* ww w. ja  va2 s .  c  om*/

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    int[] arr1 = new int[] { 1, 2, 3 };

    System.out.println(Arrays.toString(arr1));

    // copying array arr1 to arr2 with newlength as 5
    int[] arr2 = Arrays.copyOf(arr1, 5);
    arr2[3] = 4;//w  w w. j a  va2 s .c  o m
    arr2[4] = 5;

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    byte[] arr1 = new byte[] { 5, 10, 25 };

    System.out.println(Arrays.toString(arr1));

    // copying array arr1 to arr2 with range from index 1 to 7
    byte[] arr2 = Arrays.copyOfRange(arr1, 1, 7);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing long array
    long arr[] = new long[] { 1, 5, 9, 3, 7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 10 from index 1 to 3
    Arrays.fill(arr, 1, 3, 10);//from  w w w. j  a  va 2 s.  c  om

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

From source file:Main.java

public static void main(String[] args) {

    // initializing char array
    char arr[] = new char[] { 'a', 'b', 'c' };

    System.out.println(Arrays.toString(arr));

    // using fill for placing z
    Arrays.fill(arr, 'z');

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

From source file:Main.java

public static void main(String[] args) {

    // initializing unsorted int array
    int iArr[] = { 12, 1, 119, 16, 4 };

    System.out.println(Arrays.toString(iArr));

    // sorting array
    Arrays.sort(iArr);/*from w ww.java  2  s.  c o m*/

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    short[] arr1 = new short[] { 15, 10, 45 };

    System.out.println(Arrays.toString(arr1));

    // copying array arr1 to arr2 with range of index from 1 to 3
    short[] arr2 = Arrays.copyOfRange(arr1, 1, 3);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing byte array
    byte arr[] = new byte[] { 1, 6, 3, 2, 9 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 64 from index 2 to 4
    // converting int to byte
    Arrays.fill(arr, 2, 4, (byte) 64);

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    Short arr1[] = new Short[] { 15, 10, 45 };

    System.out.println(Arrays.toString(arr1));

    // copying array arr1 to arr2 as Number with range of index from 1 to 3
    Number[] arr2 = Arrays.copyOfRange(arr1, 1, 3, Number[].class);

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