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 OrderComparator
and a TypeComparator
to sort the collection based on order or type respectively.
For example, here is what your data class might look like:
public class Data{
private final String order;
private final String id;
private final String description;
private final String type;
public Data(String order, String id, String description, String type) {
this.order=order;
this.id=id;
this.description=description;
this.type=type;
}
/** getter methods here **/
}
Now, you would add them to a list and use a specific comparator to sort it:
//add data to a list
List<Data> list = new ArrayList<Data>();
list.add(new Data("Envelope","K205","Green","Paper"));
list.add(new Data("Box","J556","Yellow","Thermocol"));
list.add(new Data("Envelope","L142","White","Plastic"));
//create a comparator to sort by type
Comparator<Data> typeComparator = new Comparator<Data>() {
@Override
public int compare(Data o1, Data o2) {
return o1.getType().compareTo(o2.getType());
}
};
//sort the list
Collections.sort(list, typeComparator);