简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM