"When I Was One-and-Twenty" is a very musical-sounding poem, and much of this effect is achieved through alliteration. Overall, this helps give the poem a bright and breezy flow which is somewhat at odds with the subject of heartbreak. Perhaps the poem does this intentionally in order to suggest the way that young people tend to ignore the advice of the "wise" and need to make their own mistakes.
The first example of alliteration is across lines 1 and 2:
When I was one-and-twenty
I heard a wise man say,
The insistent /w/ sound here is playful, suggesting the once carefree attitude of the speaker. A similar early example of alliteration comes in line 6, which is part of the wise man's advice (which the speaker quotes directly): "Fancy free." The phrase also has a playful sound, contrasting light /f/ consonants with the heaviness of a broken heart. Similar alliteration is also found in lines 13 and 14 through "paid," "plenty," "sighs," and "sold." This alliteration again fits in with the musical playfulness.
Lines 7 and 8 also use alliteration through /t/ sounds:
But I was one-and-twenty,
No use to talk to me.
These are best considered together with the same sound that appears in the poem's last two lines (the equivalent section of the second stanza):
And I am two-and-twenty,
And oh, ’tis true, ’tis true.
The alliteration is one element among many that makes these two pairs of lines extremely similar. The whole point here is to show the reader that between the time of first love and of first heartbreak there is very little difference—but, in reality, everything changes. The two pairs, lines 7-8 and 15-16, are almost the same, but one relates to naive optimism and the other to melancholic understanding.