Given a list/array of strings:
You put in a broad question, so here comes an unspecific (but nonetheless) "complete" answer:
In other words: it only takes such a simple receipt to solve this problem; now it only takes your time to turn these pseudo-code instructions into real code.
For the record: if the layout of your file is really as shown above, then things become a bit easier - as it seems that your numbers are just increasing. What I mean is:
X (1) X (2) X (3)
is easier to treat than
X (1) X (3) X (2)
As in your case, it seems save to assume that the last X(n) contains the largest n. Which makes using a HashMap (as suggested by cainiaofei) a nice solution.