Both of them are wracked with guilt and sadness about the death of a loved one, particularly a death that wasn't natural or expected. Hamlet of course is grieving for his father, Hamlet Sr. and Holden is clearly unable to move on from his little brother Allie who died of leukemia.
Both characters also communicate with the dead in a way. Hamlet meets his father's ghost and from him learns that he was murdered and that Claudius is the guilty party, while Holden throughout the novel talks with and about Allie and it is clear that they are best friends, in many ways Holden still believes he is around and alive.
Another similarity would be their seeming alienation from the society which surrounds them. No one really seems to get Hamlet, they think he is mad, so too with Holden. Of course they have their moments and those they allow to start to get close, but they also have the habit of pushing people away and not allowing anyone to really be intimate with them.