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[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.put((byte) 0xFF);
    bbuf.position(5);// w  w w.  j ava  2  s  .  c  om
    bbuf.put((byte) 0xEE);
    System.out.println(Arrays.toString(bbuf.array()));
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(20);/*ww w. jav  a  2 s . c o m*/
    arrlist.add(40);
    arrlist.add(10);
    arrlist.add(15);
    arrlist.add(25);

    Object[] ob = arrlist.toArray();

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

}

From source file:Main.java

public static void main(String args[]) {
    String a[] = { "a", "b", "c" };
    String b[] = { "d", "e" };

    List<String> list = new ArrayList<String>(Arrays.asList(a));
    list.addAll(Arrays.asList(b));

    Object[] c = list.toArray();// w w w  .  jav a2s.c o  m
    System.out.println(Arrays.toString(c));
}

From source file:Main.java

public static void main(String[] args) {
    int[] data = { 1, 2, 3, 4, 5 };

    // Expand the data array to 7 elements
    int[] eData = expandArray(data, 7);

    // Truncate the data array to 3 elements
    int[] tData = expandArray(data, 3);

    System.out.println("Original  Array: " + Arrays.toString(data));
    System.out.println("Expanded Array: " + Arrays.toString(eData));
    System.out.println("Truncated  Array: " + Arrays.toString(tData));

}

From source file:Main.java

public static void main(String[] args) {
    int[] data = { 1, 2, 3, 4, 5 };

    // Copy data array to new arrays 
    int[] eData = new int[9];
    int[] tData = new int[2];
    System.arraycopy(data, 0, eData, 0, 5);
    System.arraycopy(data, 0, tData, 0, 2);

    System.out.println("Original  Array: " + Arrays.toString(data));
    System.out.println("Expanded Array: " + Arrays.toString(eData));
    System.out.println("Truncated  Array: " + Arrays.toString(tData));
}

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");

    System.out.println(stringReader.ready());

    char[] charArray = new char[10];
    stringReader.read(charArray);//www  .  j av a2  s. com
    System.out.println(Arrays.toString(charArray));

    stringReader.close();
}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random();

    // create byte array
    byte[] nbyte = new byte[30];

    // put the next byte in the array
    randomno.nextBytes(nbyte);//  ww w .j a  v  a 2s .c o  m

    // check the value of array   
    System.out.println("Value of byte array: " + Arrays.toString(nbyte));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int[] array = { 1, 2, 3 };
    // Get the value of the third element.
    Object o = Array.get(array, 2);
    System.out.println("o:" + o);
    // Set the value of the third element.
    Array.set(array, 2, 1);/*from ww  w  .  j ava2s .  c om*/
    System.out.println(Arrays.toString(array));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);

    bbuf.order(ByteOrder.BIG_ENDIAN);

    bbuf.put("java2s.com".getBytes());

    System.out.println(Arrays.toString(bbuf.array()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);// w  w w  .j  a v  a 2  s.  co m
    }

    System.out.println(Arrays.toString(queue.toArray()));
}