Hamlet's closest friend, certainly, is Horatio. Horatio has come all the way from Wittenberg for Hamlet's father's funeral, unasked, which shows both his loyalty and respect. When Hamlet mockingly suggests that Horatio actually came for his mother's wedding, Horatio responds honestly, that "it followed hard upon" his father's funeral (1.2.177). He doesn't sugarcoat a response or fawn over the prince; he is straightforward and honest, without being unkind to Hamlet's mother. Horatio also delivers the news to Hamlet that the ghost of old King Hamlet has been seen, more than once, on the castle ramparts. He seems to be Hamlet's equal in intelligence and wit, and he is certainly faithful to the prince throughout the entire play. He is the only person to whom Hamlet divulges his plans for Claudius, and Horatio keeps Hamlet's secrets. After it is clear that Hamlet will die of the wounds he sustains in the duel with Laertes, Horatio is even prepared to drink the poison left in the cup in order to accompany him in death, saying, "Here's yet some liquor left" and raising it to his lips (5.2.343). Hamlet intercepts this, and Horatio vows to tell the true story of all that happened in the Danish court.
Horatio contrasts with Rosencrantz and Guildenstern, two other students from Wittenberg, who only come to Elsinore at the king and queen's behest. They try to lie to Hamlet when he asks why they've come—they've agreed to report on his behavior back to Claudius. Hamlet is painfully aware of this. Although they do not realize they are helping a murderer, they certainly do not seem very loyal to Hamlet, especially contrasted with Horatio.