You can traverse your array and recreate it. But temporarily you can keep the accepted elements inside a dynamic data structure like Vector since you will not know the size of the array until traversing is finished.