Optimized by using Arrays.copyOf and System.arraycopy