SelamunAleykum! I'm 19 years old boy,sometimes I'm thinking of very very bad things,that things mostly are sexual fantasies,I'm thinking that things about anyone but I don't wanna think things about like that,Sometimes I feel like these thoughts take me over and move me, I think too much bad, but I don't hurt anyone, I don't want to think about it, I don't want to think about such disgusting things,I feel so bad, what do I have to do to prevent bad thoughts?Sometimes it makes me forget who I am.
Alaikumassalam wa rahmatullah,
Sexual fantasies are a natural byproduct of the body and brain’s functioning. There is no way to shut these thoughts down because they are not voluntary. What you can do is avoid acting on them as you mentioned. Putting an end to your sexual thoughts may impossible until you get older and your hormones calm down. Consider this a test like any other. Your task is to do your best to remain a good Muslim and maintain a high character by controlling your desires and not letting them cause you to sin. We cannot always be perfect, but admirable and pious young Muslims are those who go back to God as soon as they can after a sin and do not let their sins dishearten them from seeking God’s mercy and forgiveness, even if they have failed a thousand times in the past.
For more on sexual fantasies in Islam please see this page: Islam and sexual fantasies