Yes, having an erection is often a welcome experience, but they also can happen at inopportune times. It is normal for adolescent males in particular to experience random erections even without sexual thoughts or stimulation. When they occur in school or while talking to a girl you like, however, your main focus will likely be on hiding the erection and ending it as soon as possible. While simply waiting it out is often the best option, there are things you can do to possibly speed along the process.

Divert your Mind/Thoughts
You should know that the brain is the mother of all body reactions. It instructs all the other body parts to respond to stimuli, in this case when you think, see or feel the opposite sex the brain will be quick to command your nervous system that will send messages to the penis to erect therefore once it shows, try to think of something different, like remember the hard bills to pay, play a game on your phone etc. This will highly help on the erection.

Change position
Try to reposition yourself, when standing a bulge in the loins is more visible to a person in front of you, therefore try to shield away and stand in the side. While sitting try cross legging this will leave the protruding penis unnoticeable.

Excuse yourself
This is very important especially if your around people, excuse yourself and move to the wash rooms, while there rub cold water around your genitals and take time off alone for some as you distract your mind away from sex.

Hold it from the pickets
This measure is for real sharp people, try to hold your dick from the side pockets of your trouser. This will kill away the erect dick.

Take a walk.
While around people, crack a joke and walk away this will call for release of blood to your limbs so as to keep walk level less concentration of blood around your dick. Slowly the erection will die away. 

Tack In.
This is another solution that calls for pretty well sharp people to fight an erection. This minus hold your dick up wards and have it held by the belt and ensure your shirt buttons are well engaged to avoid protrusion from the above.