提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将值数组转换为双数组
//package com.nowjava; public class Main {// from 时 代 J a v a 公 众 号 public static void main(String[] argv) throws Exception { float[] v = new float[] { 34.45f, 35.45f, 36.67f, 37.78f, 37.0000f, 37.1234f, 67.2344f, 68.34534f, 69.87700f }; System.out.println(java.util.Arrays.toString(toDouble(v))); } public static double[] toDouble(float[] v) { final double[] ans = new double[v.length]; for (int k = 0; k < v.length; k++) ans[k] = (double) v[k]; return (ans); } /**来自 时代Java - nowjava.com**/ public static double[] toDouble(long[] v) { final double[] ans = new double[v.length]; for (int k = 0; k < v.length; k++) ans[k] = (double) v[k]; return (ans); } public static double[] toDouble(int[] v) { final double[] ans = new double[v.length]; for (int k = 0; k < v.length; k++) ans[k] = (double) v[k]; return (ans); } public static double[][] toDouble(float[][] v) { final double[][] ans = new double[v.length][]; for (int k = 0; k < v.length; k++) ans[k] = toDouble(v[k]); return (ans); } public static double[][] toDouble(long[][] v) { final double[][] ans = new double[v.length][]; for (int k = 0; k < v.length; k++) ans[k] = toDouble(v[k]); return (ans); } public static double[][] toDouble(int[][] v) { final double[][] ans = new double[v.length][]; for (int k = 0; k < v.length; k++) ans[k] = toDouble(v[k]); return (ans); } /** * Returns a comma delimited string representing the value of the array. */ public static String toString(double[] array) { StringBuffer buf = new StringBuffer(array.length); int i; for (i = 0; i < array.length - 1; i++) { buf.append(array[i]); buf.append(','); } buf.append(array[i]); return buf.toString(); } /** * Returns a comma delimited string representing the value of the array. */ public static String toString(double[][] array) { StringBuffer buf = new StringBuffer(); for (int k = 0; k < array.length; k++) { buf.append(toString(array[k])); buf.append(System.getProperty("line.separator")); } return buf.toString(); } /** * Returns a comma delimited string representing the value of the array. */ public static String toString(int[] array) { StringBuffer buf = new StringBuffer(array.length);