Optimized by using Arrays.copyOf and System.arraycopy

Taking your optimizations ..