Java Array Shorten toShortArray(double[][] array)

Here you can find the source of toShortArray(double[][] array)

Description

to Short Array

License

Open Source License

Declaration

public static short[][] toShortArray(double[][] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static short[][] toShortArray(double[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = (short) array[i][j];
            }//from  w w  w.j a v  a  2 s .c o  m
        }
        return ret;
    }

    public static short[][] toShortArray(float[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = (short) array[i][j];
            }
        }
        return ret;
    }

    public static short[][] toShortArray(int[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = (short) array[i][j];
            }
        }
        return ret;
    }

    public static short[][] toShortArray(long[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = (short) array[i][j];
            }
        }
        return ret;
    }

    public static short[][] toShortArray(byte[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = (short) array[i][j];
            }
        }
        return ret;
    }

    public static short[][] toShortArray(String[][] array) {
        int nr = array.length;
        int nc = array[0].length;
        short[][] ret = new short[nr][nc];
        for (int i = 0; i < nr; i++) {
            for (int j = 0; j < nc; j++) {
                ret[i][j] = Short.parseShort(array[i][j]);
            }
        }
        return ret;
    }
}

Related

  1. toShortArray(byte[] data)
  2. toShortArray(final byte[] array)
  3. toShortArray(long value, int length)
  4. toShortArray(Number[] array)
  5. toShortArray(Object[] array)