In Act 1, Scene 2, Hamlet gives strong indication that he is at least thinking about suicide in a poignant soliloquy:
O that this too too solid flesh would melt,
Thaw, and resolve itself into a dew!
Or that the Everlasting had not fix’d
His canon ’gainst self-slaughter! O God! O God!
How weary, stale, flat, and unprofitable
Seem to me all the uses of this world!
Ultimately, as he would later in the more famous "to be or not to be" soliloquy in Act 3, he decides against suicide. In that case, it is the fear of dreaming, which might interrupt the peace of sleep. In this case, it is the fact that God has declared suicide a sin.
He gives another indication of his possibily suicidal misery in Act 2, Scene 2, when he says that he will walk out of the air and "into the grave." In case the point is missed, Hamlet puns when Polonius says he will take his "leave" of Hamlet:
You cannot, sir, take from me any thing that I will more willingly part withal—except my life, except my life, except my life.
Hamlet is clearly a tormented young man, and is willing to consider even the unthinkable. But whether out of a desire for revenge or fear of the spiritual consequences, he is unwilling to do so.
This notion that Hamlet wants to commit suicide is way off base. It is not supported dramatically or thematically. In Hamlet's first soliloquy is he despondent? Does he see his life as purposeless. Absolutely. And as a typical teen he takes his despondency to extremes. In the opening lines he engages in a heightening hyperbole known as auxesis which is meant to show the depth of his emotions. It is not a clinical diagnosis of suicidal intent. His speech is also disjointed as his thoughts battle his emotions. This contrasts with Hamlet who by the end of the first act is burdened by the weight of the ghost's directives.
Don't be misled by shoddy interpretations that try in vain to justify a suicidal Hamlet as if that is Hamlet's problem through the play. It isn't. Hamlet does not want to kill himself.