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) throws Exception {
    Class<?> class1 = Class.forName("Rate");
    Object obj = class1.newInstance();
    for (Method m : class1.getMethods()) {
        if (m.getName().equals("myMethod")) {
            Class<?>[] parameterTypes = m.getParameterTypes();
            System.out.println(Arrays.toString(m.getParameterTypes()));
            Object methodArgs[] = new Object[parameterTypes.length];
            for (Class<?> parameterType : parameterTypes) {
                if (parameterType == Double.TYPE) {
                    double value = 0.5;
                    methodArgs[0] = value;
                }/*from  w  ww .j  ava 2 s. com*/
            }
            Rate rate = (Rate) m.invoke(obj, methodArgs);
            System.out.println(rate.getValue());
        }
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    arrlist.add(10);/*from   w ww .jav  a  2 s.  c  o  m*/
    arrlist.add(12);
    arrlist.add(31);
    arrlist.add(49);

    // toArray copies content into other array
    Integer myArray[] = new Integer[arrlist.size()];
    myArray = arrlist.toArray(myArray);

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

}

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.allocate(BSIZE);
    bb.put(98765);//from w w  w . jav  a  2  s .c  o m
    bb.put(98765);
    bb.put(98765);
    bb.put(98765);
    bb.put(98765);

    bb.rewind();

    double[] doubleArray = new double[BSIZE];

    bb.get(doubleArray, 0, 2);

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

}

From source file:Main.java

public static void main(String[] args) {

    LinkedList<String> list = new LinkedList<String>();

    list.add("Hello");
    list.add("from java2s.com");
    list.add("java tutorial");

    // print the list
    System.out.println("LinkedList:" + list);

    // create an array and copy the list to it
    Object[] array = list.toArray();

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

From source file:Main.java

public static void main(String[] args) {

    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("java tutorial");

    System.out.println(list);/*from ww  w.  j  a v  a 2  s. c o  m*/

    // create an array and copy the list to it
    Object[] array = list.toArray(new Object[4]);

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

}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> al = new ArrayList<String>();
    al.add("Java");
    al.add("SQL");
    al.add("Data");

    System.out.println("ArrayList:" + al);
    String[] s1 = new String[al.size()];

    String[] s2 = al.toArray(s1);

    System.out.println("s1 == s2:" + (s1 == s2));
    System.out.println("s1:" + Arrays.toString(s1));
    System.out.println("s2:" + Arrays.toString(s2));

    s1 = new String[1];
    s1[0] = "hello"; // Store hello in first element

    s2 = al.toArray(s1);/*w w  w.  ja  v a  2  s.  c  o  m*/

    System.out.println("s1 == s2:" + (s1 == s2));
    System.out.println("s1:" + Arrays.toString(s1));
    System.out.println("s2:" + Arrays.toString(s2));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedInputStream is = new BufferedInputStream(new FileInputStream("a.exe"));
    byte[] bytes = new byte[1024];
    int len = 0;/*from w  w w.  j ava  2 s  . c  om*/

    while ((len = is.read(bytes)) >= 0) {
        new CRC32().update(bytes, 0, len);
    }
    is.close();
    System.out.println(Arrays.toString(bytes));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    byte[] invalidBytes = " ".getBytes();
    byte[] validBytes = "(c)".getBytes();

    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    CharBuffer buffer = decoder.decode(ByteBuffer.wrap(validBytes));
    System.out.println(Arrays.toString(buffer.array()));

    buffer = decoder.decode(ByteBuffer.wrap(invalidBytes));
    System.out.println(Arrays.toString(buffer.array()));
}

From source file:Main.java

public static void main(String[] args) {
    List<String> colours = new ArrayList<String>();
    colours.add("red");
    colours.add("green");
    colours.add("blue");
    colours.add("yellow");
    colours.add("cyan");
    colours.add("white");
    colours.add("black");

    Collections.sort(colours);//from ww  w .jav  a2  s  .  com
    System.out.println(Arrays.toString(colours.toArray()));

    Collections.sort(colours, Collections.reverseOrder());
    System.out.println(Arrays.toString(colours.toArray()));
}

From source file:Main.java

public static void main(String[] args) {
    int[] i = shuffle(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
    System.out.print(Arrays.toString(i));
}