I want to sort a List having bean CTVo based on its group Name.
Could any body provide me a solution using Comparator.
import java.util.*;
public class
Test {
public static void main(
String[] args){
List list = new LinkedList();
CTVo vo = new CTVo();
vo.setGroupId("1");
vo.setGroupId("Fill");
list.add(vo);
vo = new CTVo();
vo.setGroupId("1");
vo.setGroupId("Fill");
list.add(vo);
vo = new CTVo();
vo.setGroupId("1");
vo.setGroupId("Fill");
list.add(vo);
Collections.sort(list);
for(int i=0;i<list.size();i++){
CTVo result = new CTVo();
System.out.println(result.getGroupName());
}
}
}
class CTVo{
private String groupId;
private String groupName;
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}