ArrayList reslist = new ArrayList(); reslist.add....
return reslist.toArray(new DeviceId[reslist.size()]);