Odrer ID Descrption Type
Envelope K205 Green Paper >>>>String Line with space in between
Box J556 Yellow Thermocol >>>>String Line with space in between
Envelope L142 White Plastic >>>>String Line with space in between
I have a table something like above and I have to provide options sort the
data based on the column name, like “sort by Order”, “Sort By Type” something like that
plz suggest me the best ideas to achieve this in Java… The table rows are strings with
space separating each touple..
Represent each row in your table as an object with order, id, description and type attributes. Add each object to a collection such as a list. You can then create different comparators such as an
OrderComparatorand aTypeComparatorto sort the collection based on order or type respectively.For example, here is what your data class might look like:
Now, you would add them to a list and use a specific comparator to sort it: