Having an erection in public is certainly embarrassing, but you don't have to panic; remember that this is a completely natural phenomenon, especially for boys going through the stage of puberty. Thankfully, there are several ways to hide or get rid of it. If you use the right techniques and wear the right clothes, no one will notice.
Steps
Method 1 of 3: Hide Erection with Clothes or Items

Step 1. Put on tight-fitting underwear
Instead of choosing wide boxers that make the erection visible and noticeable, consider using tighter briefs or trunks, which hold the penis in place while minimizing swelling.
Do not use soft silk underwear, as the friction generated on the private parts could stimulate an erection

Step 2. Cover the groin with a large object
You can use a book, a blanket, a laptop, a backpack, or anything you can keep on your lap; in this way, you hide what is happening and no one realizes the situation.
This technique is simpler in a sitting position

Step 3. Hide the erection with a long shirt
By letting it dangle below the waist up to the groin, you can prevent others from noticing an erection. Buy slightly saggy clothes that go beyond the hips and reach up to the scrotum area to "protect yourself" in these situations.

Step 4. Tie a sweatshirt or sweater around your waist
Arrange the fabric so it falls over your groin area to hide your private parts and prevent viewers from noticing your erect penis.
Method 2 of 3: Blocking Erection in the Body

Step 1. Hold the penis still with one hand in your pocket
Put your hand in the front pocket of your pants and press your penis into your leg. Maintain the pressure so that the bulge is not visible on the outside.

Step 2. Insert your penis into your underwear belt
Put a hand in your pocket, lift the penis and wedge it between the body and the elastic of the briefs; in this way, you hide the erection when you are standing or walking. For this method to be effective, it is essential that the underwear have an elasticated waist.

Step 3. Cross your legs
When you are sitting it is easier to hide what is happening; cross your legs and lock your penis between your thighs. You may feel some discomfort at first, but eventually the erection should go away.
Method 3 of 3: Get Rid of Erection

Step 1. Contract your thighs to deprive the penis of blood supply
Keep them under tension for 30 seconds or more; in doing so, the blood is drawn from the quadriceps muscles and leaves the penile area which returns to the state of rest. If this method doesn't work right away, keep contracting the muscles and combine it with another technique to get the erection through.

Step 2. Apply something cold
Cold shower water reduces erection; if you are not at home and cannot take a shower, try to press a cold object to the groin area, such as a can of soda.
Cold therapy is used in hospitals to reverse an erection that has lasted for more than four hours

Step 3. Pee
Sometimes a full bladder triggers this phenomenon, which is quite common in the morning, as soon as you wake up. Urinating may help, but if you're having trouble, you can help with the flow by taking a warm shower or bath.
The full bladder puts pressure on the sacral nerve triggering an erection

Step 4. Exercise
Light exercise such as jogging or a bike ride causes the body to send blood flow to the engaged muscles rather than to the penis, thereby returning it to a resting state. If you are too embarrassed to go outside due to an erection, do some hops on the spot and squats around the house.

Step 5. Go somewhere private until the erection passes
With the passage of time the situation resolves itself; if you can, get away and hole up somewhere. If you are in a public place, you can go to the bathroom.

Step 6. Focus on something unrelated to sex
Thinking about math equations diverts your mind and helps you get rid of an erection. Try to focus as much attention as possible on schoolwork or a game you are facing to distract yourself from what's going on. You can also reflect on something disgusting or nauseating, such as someone throwing up, to stop sexual thoughts.

Step 7. Pinch yourself
In this way, you distract the mind from the erection and bring it to the physical pain; choose a point on the arm and pinch it until the situation is resolved.

Step 8. Masturbate
If you are at home, you can do this to get rid of the erection. Excuse yourself, go to a private room and make sure you have some paper towels with you to clean up. Rub your penis until orgasm, at which point the erection should disappear.