Store and remove data

Is it possible to store data by clicking a button and when new data is to be entered, old data must be automatically removed.

For example, if i am using ultrasonic sensor and when i measured 5cm with it and click the above mentioned button 5cm must be saved to its memory and when i measure 13 cm and press the same button it must display 13cm not the 5cm.

Yes, this is possible.

The IDE is packed with worked examples, and most libraries also have device-specific examples