是dataset.addSeries需要的參數如下所示(java.lang.Comparable key, double[] values, int bins, double minimum, double maximum)
使用dataset.addSeries與龍[]值
現在,我想在double[] values
領域使用一個名爲Long[] v1
變量,並不能弄清楚如何轉換它。
是dataset.addSeries需要的參數如下所示(java.lang.Comparable key, double[] values, int bins, double minimum, double maximum)
使用dataset.addSeries與龍[]值
現在,我想在double[] values
領域使用一個名爲Long[] v1
變量,並不能弄清楚如何轉換它。
從喬恩斯基特的回答上How to convert array of floats to array of doubles in Java?,我引用:
基本上東西要做的每個值的轉換。 不是兩個數組類型之間的隱式轉換,因爲在JITting之後用於處理它們的代碼將會不同 - 它們具有不同的元素大小,並且long將需要轉換,而 則不會。與此相比,陣列協方差爲參考 類型,其中,讀取數據時不轉換是必需的(在 位模式爲String引用作爲對象引用, 例如相同的)和元件大小爲所有參考相同的類型。
總之,東西將不得不在一個循環中執行轉換。 I 不知道任何內置方法來做到這一點。我確定它們存在於第三方庫中,但除非您碰巧使用過這些庫中的一個 ,否則我只需編寫自己的方法。
以下爲適應實施喬恩的回答適合你的問題:
public static double[] convertLongsToDoubles(Long[] input)
{
if (input == null)
{
return null; // Or throw an exception - your choice
}
double[] output = new double[input.length];
for (int i = 0; i < input.length; i++)
{
output[i] = input[i];
}
return output;
}
你將不得不這樣做自己。
寫一個方法,爲您做轉換。
public static double[] convertFromLongToDouble(Long[] l) {
double[] doubleArray = new double[l.length];
// .. iterate through the Long array and populate to double array
return doubleArray;
}
從這個答案剽竊Jon Skeet:http://stackoverflow.com/a/2019374/19679。如果你要偷,我想是最好的。 –