Before Hamlet gets on the ship, he begins to use his innate intelligence to discern the true characters of his former friends, the turncoasts, Rosencratz and Gildenstern. He compares them to sponges "that soak up the King's countenance,/his rewards, and authorities.../When he needs what you have gleaned, it is but squeezing you, and sponge, you/shall be dry again" (4.2.15-21).
When he embarks on the forced journey (ordered by Claudius), Hamlet hears of the movements of Fortinbras and begins to wonder about himself. First, he thinks about how reason alone separates men from beasts: "What is a man/If his cheif good and market of his tim/Be but to sleep and feed? A beast, no more," he proclaims (4.4.35-37)
While biding his time on the ship, Hamlet challenges his own intergrity and bravery. He knows the time has come to act to avenge his father, punish his mother and uncle, and halt Fortibras encroachment:
I do not know
Why I live live to say "This thing's to do."
SIth I have cuase, and will, and strength, and means
To do 't. Examples gross as earth exhort me..." (4.4.45-59).
By the time the story of the ship concludes, Hamlet has strengthened his resolve to act on his principles.