The length is badgeArray.length(). You can initialise the list in the individual cases instead of at the top when you don't know this yet.