James compares the hearts of King Saul and King David, and looks at how Saul's heart was different from God's heart. But, David was a man after God's own heart. He was more interested in the Lord's purpose than his own self worth or what others thought of him.
6 And it came to pass, when they were come, that he looked on Eliab, and said, Surely the LORD’S anointed is before him. 7 But the LORD said unto Samuel, Look not on his countenance, or on the height of his stature; because I have refused him: for the LORD seeth not as man seeth; for man looketh on the outward appearance, but the LORD looketh on the heart.
14 But now thy kingdom shall not continue: the LORD hath sought him a man after his own heart, and the LORD hath commanded him to be captain over his people, because thou hast not kept that which the LORD commanded thee.