I have the following code and I wish to know if that is the correct way to return the Array.
my function returns Page<byte[]>[]
(an Array of Page<byte[]>
), and I'm using ArrayList as the container.
pages is a private HashMap member. Page is an object I created that have a member of a generic type T.
in the end I return my ArrayList casted with toArray, but I can't just tell it to cast it to Page array object, it needs a fixed size (new Page[pageArray.size()]) and I think that this is not the right way to do that.
What is right way?
public Page<byte[]>[] getPages(Integer[] pageIds){
ArrayList<Page<byte[]>> pageArray = new ArrayList<Page<byte[]>>();
for (int pageId : pageIds){
if (pages.containsKey(pageId)){
pageArray.add(pages.get(pageId));
}
}
return pageArray.toArray(new Page[pageArray.size()]);
//return pageArray.toArray(Page);