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[]) {
    List<Integer> dataList = new ArrayList<Integer>();
    for (int i = 0; i < 10; i++) {
        dataList.add(i);//w  w  w.j a v a 2  s .c  o  m
    }
    Collections.shuffle(dataList);
    int[] num = new int[dataList.size()];
    for (int i = 0; i < dataList.size(); i++) {
        num[i] = dataList.get(i);
    }
    System.out.println(Arrays.toString(num));
}

From source file:Main.java

public static void main(String args[]) throws IOException {

    Process process = new ProcessBuilder(args).start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;//from   www. j  a v a2s  .  co  m

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

}

From source file:Main.java

public static void main(String args[]) throws IOException {

    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(args);
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;//from  w w  w .  ja v a2 s  .  co m

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

}

From source file:Main.java

public static void main(String[] args) {
    int[] nums = new int[100];

    for (int i = 0; i < nums.length; ++i) {
        nums[i] = i + 1;//from   ww w . j ava2 s. co  m
    }

    Random generator = new Random();
    for (int i = 0; i < nums.length; ++i) {
        int arrayIndex = generator.nextInt(nums.length - i);
        int tmp = nums[nums.length - 1 - i];
        nums[nums.length - 1 - i] = nums[arrayIndex];
        nums[arrayIndex] = tmp;
    }
    System.out.println(Arrays.toString(nums));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL u = new URL("http://www.google.com");
    InputStream in = u.openStream();
    MessageDigest sha = MessageDigest.getInstance("SHA");
    byte[] data = new byte[1024];
    int bytesRead = -1;
    while ((bytesRead = in.read(data)) >= 0) {
        sha.update(data, 0, bytesRead);/*  w w w.j  av a  2 s  . c o m*/
    }
    byte[] result = sha.digest();
    System.out.println(Arrays.toString(result));
    System.out.println(new BigInteger(result));
}

From source file:Main.java

public static void main(String[] argv) {
    // Create the sorted set
    Set<String> set = new TreeSet<String>();

    set.add("b");
    set.add("c");
    set.add("a");

    Iterator it = set.iterator();
    while (it.hasNext()) {

        Object element = it.next();
        System.out.println(element);
    }// w ww  .j  a  va 2 s . c  o m

    // Create an array containing the elements in a set
    String[] array = (String[]) set.toArray(new String[set.size()]);
    Arrays.toString(array);
}

From source file:Main.java

public static void main(String args[]) {
    int rnd;/*from   w w  w.  ja  v a2 s.c  o m*/
    Random rand = new Random();
    int[] nums = new int[50];

    boolean[] check = new boolean[50];

    for (int k = 0; k < 50; k++) {
        rnd = rand.nextInt(50);
        //check if the check array index has been set
        //if set regenerate since it is duplicate 
        while (check[rnd]) {
            rnd = rand.nextInt(50);
        }
        nums[k] = rnd;
        check[rnd] = true;
    }
    System.out.println(Arrays.toString(nums));

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.write(1);/*  ww  w  .  j a  v  a 2 s  .  com*/
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeByte(1);/*from  w w w  .  j av a  2s .  c om*/
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeShort(1);/*from   ww w .ja  v  a2s  .co m*/
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}