Susheel Singh
Susheel Singh

Reputation: 3854

how to save csv like text file in an ArrayList to sort by name

i have the below format of textfile:

1345, Mike Douglas, 102, 120, 100, 322 
1879, John Bobber, 200, 180, 120, 500 
2560, Andrew Beck, 150, 300, 150, 600 
3212, Rick Water, 200, 100, 140, 440

I need to read this file and store it in an ArrayList. But I am not getting an Idea which way of storing would be better, so that I can sort the data based on name later on. please someone throw light on it. I am not asking for code, just an idea and i would implement it.

what I have in my mind is to store each line in a ArrayList but how to sort it later on is my problem.

Upvotes: 0

Views: 80

Answers (1)

Alexis C.
Alexis C.

Reputation: 93842

Create a class, let's called Person. Then read each line, split it to get the different parts, create a new Person and add it to the list. Then sorting it later would be easy, providing a custom comparator to Collections.sort, telling that you want to sort your List based on person's name.

Upvotes: 3

Related Questions