Praise be to Allah, the Lord of the Worlds; and may His blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
Getting married is the only lawful way of fulfilling sexual desires. That’s why the Prophet (Sallallahu Alaihi wa Sallam) advised the youth to get married.
Al-Bukhari and Muslim reported that Ibn Masoud narrated that the Prophet (Sallallahu Alaihi wa Sallam) said: O, young people whoever among you can marry, should marry, because it helps him lower his gaze and guard his modesty (i.e. his private parts from committing illegal sexual intercourse, etc.)
So, if one can get married, then it is good, otherwise Islam has set some measures that help one to protect one's private parts:
1. A Muslim should spend his time in the obedience and remembrance of Allah, in order to fill his heart with Iman and therefore increase his fear of Allah.
2. To fast: the remaining text of the above Hadith is: "and whoever is unable to marry, should fast, as fasting diminishes one's sexual power."
3. To keep company with pious and righteous people, so that they remind him if he forgets, and help him if he remembers.
4. To close the doors that lead to inciting or arousing one's desires, like the forbidden looking, staying in seclusion with alien women, touching, etc.
Allah knows best.