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) {

    byte[] arr1 = new byte[] { 5, 15, 25 };

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

    // copying array arr1 to arr2 with newlength as 5
    byte[] arr2 = Arrays.copyOf(arr1, 5);
    arr2[3] = 0;/*  www.ja v a 2  s.c o  m*/
    arr2[4] = 1;

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

From source file:Main.java

public static void main(String[] args) {
    int[] unsorted = { -3, 10, -4, 11, 5, 1, 2 };
    System.out.println(Arrays.toString(unsorted));
    int[] sorted = unsorted;
    Arrays.sort(sorted);//from   www  .jav  a  2 s  .  c o m
    System.out.println(Arrays.toString(sorted));
    int breakingPoint = Arrays.binarySearch(sorted, 5);
    for (int i = breakingPoint; i < sorted.length; i++) {
        System.out.println(sorted[i]);
    }
}

From source file:Main.java

public static void main(String[] args) {
    boolean[] arr1 = new boolean[] { true, false };

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

    // copying array arr1 to arr2 with newlength as 4
    boolean[] arr2 = Arrays.copyOf(arr1, 4);

    // printing the array arr2
    System.out.println(Arrays.toString(arr2));
}

From source file:Main.java

public static void main(String[] args) {

    char[] arr1 = new char[] { 'j', 'a', 'v' };

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

    // copying array arr1 to arr2 with newlength as 5
    char[] arr2 = Arrays.copyOf(arr1, 5);
    arr2[3] = 'a';
    arr2[4] = '2';

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

From source file:Main.java

public static void main(String[] args) {

    short[] arr1 = new short[] { 1, 10, 25 };

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

    // copying array arr1 to arr2 with newlength as 5 as Object
    Object arr2 = Arrays.copyOf(arr1, 5);

    // cast arr2 as short in order to be printable
    short[] arr3 = (short[]) arr2;

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

From source file:Main.java

public static void main(String[] args) {

    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
    Object arr2 = Arrays.copyOfRange(arr1, 1, 3);

    // cast arr2 as short in order to be printable
    short[] arr3 = (short[]) arr2;

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

From source file:Main.java

public static void main(String[] args) {

    float[] arr1 = new float[] { 10f, 30f, 50f };

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

    // copying array arr1 to arr2 with range of index from 1 to 4
    float[] arr2 = Arrays.copyOfRange(arr1, 1, 2);
    arr2[3] = 90f;/*from  w  w w .  j a v  a2s .com*/
    arr2[4] = 100f;

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

From source file:Main.java

public static void main(String[] args) {

    float arr[] = new float[] { 1f, 2f, 3f, 4f, 5f };

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

    // using fill for placing 12 from index 1 to 3
    Arrays.fill(arr, 1, 3, 12f);/*from   w w w.  ja  va2  s .  c om*/

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

From source file:Main.java

public static void main(String[] argv) {
    String str = "java2s.com";
    char[] chars = str.toCharArray();
    System.out.println(Arrays.toString(chars));
}

From source file:Main.java

public static void main(String[] args) {

    boolean arr[] = new boolean[] { true, true, false };

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

    // using fill for placing false
    Arrays.fill(arr, false);/*from  w ww . j a v  a2 s  . c  om*/

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