在Java中,我想将一个short []转换为double [] [英] In Java, I want to convert a short[] to a double[]

查看:177
本文介绍了在Java中,我想将一个short []转换为double []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 short [] 数组:

short[] buffer = new short[bufferSize];

我有一个方法作为参数类型 double [] ,所以我不能按原样传递。我需要把它变成一个 double [] 。我做的最好的事情是创建一个新的对象并循环并转换,如下所示:

I have a method that takes as a parameter type double[], so I cannot pass it as-is. I need to make it into a double[]. The best thing that I've done is to make a new object and loop through and convert, like this:

double[] transformed = new double[bufferSize];

for (int j=0;j<bufferSize;j++) {
    transformed[j] = (double)buffer[j];
}

我还没有测试过上述方法,但我想知道是否有这是一个更好的方法吗?

I have not yet even tested the above approach, but I am wondering if there is a better way to do this?

谢谢。

推荐答案

尽管您可以使用 buffer.length 而不是 buffersize

That's as good as it gets, though you can just use buffer.length instead of buffersize.

这篇关于在Java中,我想将一个short []转换为double []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆