I am reading following data –
Year, No, Name,
2009, 1, ABC
2009, 2, PQR
2009, 3, XYZ
2010, 1, BCD
2010, 2, DEF
2010, 3, JKL
2011, 1, FGH
2011, 2, IJK
2011, 3, LMN
Its a sample, there are thousands of these type.
I need to display the unique Year value in JList and for the selected Year, I have to give a CheckBox, which if selected, would display the Name sorted on No, otherwise sorted on Name.
What you need looks like a
Map, key will be theYear, and value will be a list ofNoandNumber(you need to create your own class).Then you need to create two
Comparator, one is based onName, the other isNo. So when checkbox is checked, you useName-based comparator to sort the list, when unchecked, useNo-based comparator to sort the list.