As masturbation is haram in Islam and sexual urge is a natural thing , so , what a young unmarried person should do when a sexual urge comes?
The Prophet Muhammad (PBUH) said:
“O young men, whoever among you can afford to, let him get married, for it is more effective in lowering the gaze and in guarding one’s chastity. Whoever cannot afford it, then let him fast, for it will be a shield for him.”
This is addressed to young men, but it also includes young women.
Another version which says the same thing:
“ O young men, those among you who can support a wife should marry, for it restrains eyes from casting (evil glances). and preserves one from immorality; but those who cannot should devote themselves to fasting for it is a means of controlling sexual desire. “ (Muslim, Kitab un-Nikah, 3231)
This Hadith clearly explains that you should fast as it will control your sexual desire.
Other than that, don't look at haram things. Try and not even think about sex and related subjects. Ask Allah to help you deal with sexual desires.
Source: Islam Q&A