Java examples for java.lang:int Array
1-D Integer array to float array.
// This library is free software; you can redistribute it and/or //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int[] array = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(java.util.Arrays.toString(toFloat(array))); }// w w w .java2 s . c o m /** * 1-D Integer array to float array. * @param array Integer array. * @return Float array. */ public static float[] toFloat(int[] array) { float[] n = new float[array.length]; for (int i = 0; i < array.length; i++) { n[i] = (float) array[i]; } return n; } /** * 2-D Integer array to float array. * @param array Integer array. * @return Float array. */ public static float[][] toFloat(int[][] array) { float[][] n = new float[array.length][array[0].length]; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[0].length; j++) { n[i][j] = (float) array[i][j]; } } return n; } /** * 1-D Double array to float array. * @param array Double array. * @return Float array. */ public static float[] toFloat(double[] array) { float[] n = new float[array.length]; for (int i = 0; i < array.length; i++) { n[i] = (float) array[i]; } return n; } /** * 2-D Double array to float array. * @param array Double array. * @return Float array. */ public static float[][] toFloat(double[][] array) { float[][] n = new float[array.length][array[0].length]; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[0].length; j++) { n[i][j] = (float) array[i][j]; } } return n; } }