The ordinal article haš·šê·nî is most commonly translated as ‘the second’, although the ESV translation is ‘that youth’. The use of this ordinal article denotes a change in subject from the king (the original subject) to the youth (a secondary subject), before reverting back to the king.
Better was a poor and wise youth than an old and foolish king who no longer knew how to take advice. 14 For he went from prison to the throne, though in his own kingdom he had been born poor. 15 I saw all the living who move about under the sun, along with that[b] youth who was to stand in the king's[c] place. 16 There was no end of all the people, all of whom he led. Yet those who come later will not rejoice in him. Surely this also is vanity and a striving after wind.
In this translation, the relevant notation is: [b] the second; [c] his, which offers a more direct translation, but one which is less clear in English.
The author appears to be referring to the potential of the poor and wise youth, compared to that of an old and foolish king who no longer heeds advice and thus has nothing to look forward to except his inevitable death. After his death, the people he led (including this youth he considers better than the king) will continue, and later generations won’t value this old and foolish king in the way he currently enjoys.
The ‘vanity and striving after the wind’ in this case refers to the pointlessness of having ‘arrived’ at the summit of power and influence in a temporary life.