Hamlet's line is the most famous existential line ever uttered. The question can be paraphrased as to exist or not to exist. In his spiritual malaise and oppressive melancholy brought about by the death of his father and the lack of loyalty exhibited by his mother who quickly marries her husband's brother, Hamlet ponders ending his life. However, as he debates this metaphysical question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them? (III, i, 56-60)
Hamlet reasons that people do not end their woes and tribulations because they do not know if they may have to face worse burdens in the next life after death. And, thus, Hamlet concludes,
Thus conscience does make cowards of us all;
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought,
And enterprises of great pith and moment
With this regard their currents turn awry,
And lose the name of action. (III, i, 83-88).
With such cowardice wrought by conscience, Hamlet perceives that man is yet dead when he has lost his courage and strength of action. This despair in man's existence is later reflected in another metaphysical remark of Hamlet's in the next scene: "...for there is nothing either good nor bad, but thinking makes it so (II, ii, 241). Truly, Hamlet understands the "absurdity of existence" as such Existentialists as Jean-Paul Sartre much later described it.
This line is the opener for Hamlet's most famous and quoted soliloquy. In this speech, he ponders whether life is worth living or not. He personally feels that it isn't, but says that the reason that many of us don't end our lives sooner is because our fear of the unknown--death--is stronger than our misery while alive. We are so afraid of not knowing what--if anything--happens after death that we stick with what we know here in life even if it is awful. So, "to be or not to be" means, "Is life worth living? I am pondering, right now, whether I should stay alive (be) or die (not to be)."
The question is, is it better to be alive than dead? Is it nobler to put up with all the nasty things that luck throws your way, or to fight against all those troubles by simply putting an end to all of them at once? Hamlet is trying to decide if he should let go of his anger towards his uncle and mother, or if he should seek revenge. He knows that if he decides to seek revenge that it may result in the end of his life.