Add delete and replace in C++ & Java