Mass of trolley = 0.5 kg
Velocity = 2 m/s
When the compressed spring is released, its potential energy is converted into kinetic energy completely.
Potential energy of compressed spring = kinetic energy of moving trolley
Kinetic energy of trolley = 1/2 x mass x (velocity)2
= 1/2 ×0.5 ×(2)2
= 1/2 ×0.5 ×2×2=1J
Hence, potential energy of compressed spring = 1.0J