Does your apartment building allow pets?
What I tell anyone who is looking at getting a new puppy: You shouldn't unless you have the money (vet bills, grooming, if needed, etc.), time (puppies especially need a lot of training time and dogs are very social animals), energy (most breeds need a lot of exercise and playtime. They really suffer mentally and physically, if those needs aren't met), and patience (training takes a lot repeating yourself and staying calm when they mess up. Positive reinforcement works better than negative.). One other thing about dogs, you also have to be ready to pick up their excrement (lots of devices on the market that keep hands far away from the waste.)
You should also never get a puppy as a "spur-of-the-moment" type purchase. IF you really want a dog, I suggest researching breeds that do well in apartments and city living. Then either adopt from a shelter or a breed specific rescue or find a reputable breeder in your area and buy a purebred from them. If you are unsure about breeds, you might even look at breeders in your area and contact them to find out more before making a decision.
If you really want an animal companion, you need to remember, that most cats and small to medium size dogs can live to be 15-20 years old. They are a long term commitment.
If you are unsure about getting a pet or what type to get, you might ask here:
Other Pets & Animals - Ask Me Help Desk. The experts on the pet forums can give you ideas on a variety of animals to think about.
That said. It is up to you to decide what your needs are. IF you decide to get a pet, I recommend taking at least a month to research what type would be best for you and your life-style. The research alone might help you fill part of the loneliness that you are feeling.