Salam Dear Brother,
Thank you for your question and for contacting Ask About Islam.
This question reminds me of the story of the man who asked two of his acquaintances about how did they find the people of the town they just visited. The first man said that its people were very pious while the second man said the complete opposite that its people were very corrupt.
Upon that, the man asked which places they visited and the first man said that he visited the masjids and was looking for circles of knowledge, while the second man said that he went to places of amusement where people drink alcohol and meet women.
The moral behind the story is very clear, what is it that one is looking for? What is the intention of the person whether he is attending college or working? If he is looking for women to meet then he will find what he is looking for; but if he is a serious person who does not take his religion lightly then such matters will not shake him.
During my college days, a single Muslim friend of mine had to go to New York for his mother’s treatment. At the hospital, there was a beautiful nurse who was attracted to him. She found his address from the hospital records and went to his residence. She offered herself to him but my friend refused even though he was also tempted.
My friend was young and handsome and could have fulfilled his desires without anyone knowing but he remembered that he has a lord watching him and that he cannot betray his lord and his religion.
Now, I may answer your question. A Muslim needs to have a strong will and lower his gaze. If he wishes to marry then there are proper Islamic channels to follow. If he cannot marry then he should fast as the Prophet (peace be upon him) had advised. 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 refrain from looking at other women, and save his private parts from committing illegal sexual relation; and he who cannot afford to marry is advised to fast, as fasting will diminish his sexual power.” (Al-Bukhari)
Of course, there is no better advice than the Prophet’s advice but as a Muslim brother I can also advise you to exercise if you cannot fast often as exercise has more or less the same effect.
Also part of it is having too much free time. So fill that free time with something useful, whether it is exercise or even getting a part time job if you are a student.
My final advice is to keep up with the Islamic rituals such as performing the five daily prayers, reading the Quran, and fasting whenever possible.
Also know how to choose your friends. Make sure that they are pious and they encourage you to keep your faith strong.
Being attracted to a woman that you will not be able to marry will only put lots of pressure on you uselessly. Leave this to your future partner. There is a proper time for everything so know when is the proper time for you to marry.
Finally, remember that Allah is testing you and Shaitan is tempting you so be patient with Allah’s test and do not fall into the trap of the Shaitan.
I hope this helps answer your question.
Salam and please keep in touch.