Narrated Alqama: While I was walking with Abdullah, he said, “We were in the company of the Prophet, peace be upon him, and he said, ‘He who can afford to marry should marry. Because it will help him to lower his gaze and save his private parts (from committing illegal sexual acts, etc.).

He who cannot afford to marry is advised to observe Fasting, as Fasting will diminish his sexual power’.”
[3: 129- O.B. Sahih Al-Bukhari)