Java how to sort from Text File



CH0001 , John
CH0002 , Alex

Above is the coach.txt which contains id and name. I’m still new to Java. How do I sort it according to the name.

CH0002 , Alex
CH0001 , John

My expected output would be like this. Kindly appreciate for you guys help!

Answer

There are many alternatives.

The main issue here should be comparing the lines not according to the alphanumeric value of the whole line, but separating the lines into columns, and using the second column’s alphanumeric value as the comparator.



Source: stackoverflow