I think it is entirely possible that Shakespeare wrote the “To be or not to be” soliloquy as a separate piece expressing his own personal feelings about life and death and then put it away in the bottom drawer, as writers will do, until he found a convenient spot for it when he was writing his play Hamlet. What is important in this soliloquy, and what explains its great popularity, is the truths it tells about human existence, not what it reveals about the character of the moody Prince. We have all personally experienced some of the slings and arrows Hamlet complains about, just by being alive and having to deal with people and struggle to keep a niche in the crowded, competitive world. And we have all felt discouraged and wondered whether existence was really worth the trouble.
If we haven’t experienced all the slings and arrows personally, we have seen others suffering and have wondered why some people will continue to cling to life when they get nothing out of it but hard work and suffering. If we live in a city we commonly see people who are totally blind trying to find their way by feeling the pavement with long white canes. We see men sleeping in doorways on the cold concrete. We see men rummaging through dumpsters and trash receptacles trying to gather a few cans and bottles they can sell for enough to live on for one more day. We see all sorts of ugliness and deformity. We see old people hobbling along, hoping to survive just a little bit longer, although they have nobody to care whether they live or die.
Shakespeare itemizes some of the negative aspects of human existence in this soliloquy. They deserve more attention than the worn-out questions of what Hamlet is really thinking about or whether he is really contemplating suicide. We have all personally experienced “the proud man’s contumely,” “the pangs of despised love,” and “the insolence of office” (if only at the Department of Motor Vehicles).
Charles Dickens’s novels offer excellent examples of some of the “outrageous fortune” which Hamlet summarizes in just a few lines. In his novel Bleak House, Dickens describes the effects of “the law’s delay” in the interminable case of Jarndyce v Jarndyce, during which the lawyers of his day, like a flock of vultures, picked the estate clean and left nothing but the bare bones. In his novel Little Dorrit, Dickens illustrates “the proud man’s contumely” and “the insolence of office” in his characters’ dealings with the Circumlocution Office. In that great novel, his character Daniel Doyce, who has been trying for years to patent an invention, is an example of “the spurns that patient merit of th’ unworthy takes,” while both Little Dorrit, who loves Arthur Clennam, and Arthur Clennam, who loves "Pet" Meagles, offer good examples of “the pangs of despised love.”
Shakespeare was probably talking for himself when he wrote those famous lines beginning with “To be, or not to be.” He had had a rough life and knew—better than any spoiled prince--what it was like to have to struggle for survival in a brutal city like London of the sixteenth century. How could he have written them otherwise?