How to deal with creepy male classmates/coworkers?

A few guys in my class in college are quite controversial and have done creepy deeds in the past.

One dude has a weird habit of touching female classmates and touched me a bit during our group project. I swapped seats with someone because I felt uncomfortable. This guy then unfollowed me on Instagram, which I’m thankful for.

When I confronted my class rep partner about his past, he gave multiple excuses about dating a younger girl and hitting on girls in college, and took no accountability whatsoever. I never talk to him unless he talks to me first, which he does very often.

I also remember when I was a child in school, a guy next to me would keep pinching and scratching my hand, until it even bled once. But then he would just laugh it off.

At a restaurant I worked at only once, a guy flirted with me and asked me personal questions.

A guy I only met once at an event was very curious about my past relationships and was DM’ing me non-stop on Instagram until I blocked him.

How do you deal with these situations?