It struck me how much of Sefer Shmuel is dedicated to contrasts: Specifically between David Hamelech--King David--and everybody else.
Here are two examples:
1) In Chapter 22, David flees from Shaul to Maalot Adulam, and who "gathers around" him ? Desperate people, people pursued by creditors, people who are bitter of soul.
Where have we seen this before? With Yiftach, in Shoftim Chapter 11, Yiftach flees from his brothers, and he becomes the leader of a group of "empty men."
2) In the end of Chapter 25, Shaul takes his daughter Michal--David's wife-- and marries her off to another man, Palti ben Layish. This, too, we saw with Shimshon, when his wife was given over to another man, at the end of Chapter 14 of Sefer Shoftim.
Of course, there are also contrasts to be had with Shaul-- that is a discussion for another time. But what is the significance of these contrasts?
It seems that David's good behavior/responses is being contrasted with the unfavorable responses of those who preceded him when faced with similar trials. Yiftach, as we saw, is one of the worst of the Shoftim. David is clearly viewed favorably (overall) by the prophets. Yet both have, early in their careers, a role as the leader of a group of vagabonds. Their commonality draws attention to their differences. Here, in David, is the king who is the antidote to the terrible period of the Judges.
Shimshon, as well, was one of the worst of the Shoftim. His response to having his wife taken from him was revenge (in the incident with the foxes and the torches). David's was to wait until he was king, and to demand Michal back. (In Chapter 3 of Shmuel 2). Now certainly, Palti ben Layish was crying all the way at the loss of his wife. But we have no indication that David knew of this.
In sum: There are parallels in the life of David to events in the lives of the Judges. My suggestion is that these parallels are told to us to encourage us to compare and contrast David with those Judges. The period of Judges was untenable, and a king was needed. The book of Samuel is trying to show what was right about David, how he was the ideal king.