Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array becoming null when List.toArray is used

Tags:

java

arrays

I'm having an issue where I'm trying to populate an Array with values from a list, then replace the old values with the new ones upon each call of the method. The code below works once, then the next attempt it gives no errors until the new array variable is used , as the array which should have been populated with list data just is full of null values. If anyone has any suggestions much appreciated.

Integer[] stockFF2 =new Integer[ordersBFList.size()]; 
Integer[] ordersFF2 =new Integer[stockBFList.size()];
stockFFList.toArray(stockFF2);
ordersFFList.toArray(ordersFF2);
like image 770
Moley Avatar asked Oct 25 '25 18:10

Moley


1 Answers

I think you have got the sizes wrong (orderFF2 and stockFF2 are using the sizes of each other's lists). I suspect one of the arrays is populated properly - one with the larger array - while the other allocates and returns a new array with the elements you want keeping the passed in array as it was because it is too short.

like image 55
MAK Avatar answered Oct 27 '25 08:10

MAK