i have a file which looks something like this,
111, X, 12, 34, 56
111, Y, 12, 34, 56
122, X, 12, 34, 56
122, Y, 12, 34, 56
133, X, 12, 34, 56
133, Y, 12, 34, 56
now i have parsed this data and am storing individual records in a class and then accessing them and everything is fine.
but i need to further group this data based on the 2nd record (X and Y). and then I need to process the individual records in different ways. i mean i need to somehow group the records and then parse them. please help. thanks.
posted 11 years ago
i have tried to implement the Comparator class.
and have also written a compare method. but am not sure how i would implement it.
Use a Map<String,List><Record>> where Record is the class representing each row.
Adding is quite easy:
Afterwards, the map contains a List<Record> for each different value of the second field. You can use the map's keySet(), entrySet() and values() methods to iterate over all keys, entries and values (which are List<Record>).