将double []转换为long []

0 java arrays double long-integer

好像标题所说,我必须转换double[]为a long[]但我不知道我该怎么做.

我试试这个:

double[] ids = getIds(); // The ids I'm getting return in double format
List<Long> myArray = new ArrayList<Long>();

for (double _ids : ids) {
    myArray.add((long)_ids);
}

System.out.println(myArray); // Works! the list is now long, I can print also in myArray.toArray()

// Now I need pass this on a long[] array for the system wich request the data
// Receive "getStringsById(String string, long... Ids)"
Run Code Online (Sandbox Code Playgroud)

我非常感谢你的帮助.

谢谢你的时间.

rge*_*man 5

创建一个long[]而不是创建一个List<Long>,需要调用toArray()才能得到一个long[].

long[] myArray = new long[ids.length];
int i = 0;
for (double _ids : ids){
    myArray[i++] = (long) _ids;
}
Run Code Online (Sandbox Code Playgroud)