What is the technical difference between a hydraulic cylinder and a spring? For sure, I understand their principles but I wonder about physical-technical differences. For example, the most obvious aspect (for me), is that they both can deflect. A spring, on the contrary, can store potential energy, is this also valid for the cylinder? It is also able to oscillate. Are there more differences?
A hydraulic cylinder filled with hydraulic fluid cannot deflect unless the fluid has somewhere to go. It cannot act as a spring unless the reservoir has the capability to absorb the fluid and the ability to maintain a restorative pressure during compression. In a simple system this would be a spring and at that point you are asking, "Would a spring act like a spring?".
Figure 1. A compact hydraulic power unit. Image source: ResearchGate.
@Ben This is to answer the comment whether there are configurations that a hydraulic cylinder acts as a spring.
Please Note that with the term hydraulic cylinder, I consider any cylinder with a hydraulic fluid that can act as an actuator.
Automotive shock absorber:
The following is an automotive shock absorbed. Notice the use of oil and gas (usually nitrogen). This type of shock absorved acts like a spring (the gas compresses) and a dashpot (the piston in the oil).
Figure 1: This is an automotive shock absorber (source: aresmotorsports)
Connected hydraulic cylinders
The following image are two connected hydraulic cylinders.
Figure (2): connected hydraulic cylinders (source: University of Alaska Fairbanks
In this configuration you can place a dead weight on one of the two cylinders. Then by applying a force on the other end, the vertical motion of the cylinder effectively stores potential energy.