Being alone is a state.
Loneliness is nothing more than a thought. It's not a feeling, it's just a thought that enters your mind. When you're alone and not busy engaging in an activity, a thought might enter your head and tell you that you're feeling lonely. This is incorrect. If you choose to believe in this passing thought, then you will feel even more frustrated and sad.
If you were alone and engaged in a hobby or activity that you love to do (could be anything), or if you're exerting a lot of mental power eg studying or reading books, then you're distracted from your thoughts and you won't feel 'lonely'.
This thought isn't necessarily related to the state of being alone. Some people feel lonely even if they're surrounded by friends, or if they're in a crowded place. It's important to recognise that this is just a thought which enters your head when you're not being distracted by something else.
It is a thought. Different people decide to deal in different ways with this thought when it enters their minds.
I recommend Noah Elkrief's videos about loneliness on YouTube, he hits the nail right on the head.