Here you can find the source of truncateNaN(double[] values)
Parameter | Description |
---|---|
values | array to truncate |
value | value to remove from the end of the array |
public static double[] truncateNaN(double[] values)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww . ja v a 2 s .c o m*/ * truncates the given array by removing all fields at the end that contain * the given value, e.g., {0,1,0,2,3,0,0} => {0,1,0,2,3} for value=0 * * @param values * array to truncate * @param value * value to remove from the end of the array * @return truncated array */ public static double[] truncateNaN(double[] values) { if (!Double.isNaN(values[values.length - 1])) { return values; } int index = values.length - 1; for (int i = values.length - 1; i >= 0; i--) { if (!Double.isNaN(values[i])) { break; } index--; } double[] valuesNew = new double[index + 1]; System.arraycopy(values, 0, valuesNew, 0, index + 1); return valuesNew; } }