就像标题所说的那样,我必须将double[]
转换为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)"
我真的很感激帮助。
感谢您的时间。
答案 0 :(得分:5)
创建long[]
而不是创建List<Long>
,这需要调用toArray()
才能获得long[]
。
long[] myArray = new long[ids.length];
int i = 0;
for (double _ids : ids){
myArray[i++] = (long) _ids;
}