标签:java
public class ZoneComparatorName implements Comparator<ZoneDTO> {
@Override
public int compare(ZoneDTO Z1, ZoneDTO Z2) {
String name1 = Z1.getName();
String name2 = Z2.getName();
if (name1.compareTo(name2) > 0)
{
return 0;
}
else
{
return -1;
}
}
}
public class ZoneComparatorStreet implements Comparator<ZoneDTO> {
@Override
public int compare(ZoneDTO Z1, ZoneDTO Z2) {
int age1 = Integer.parseInt(Z1.getStreet());
int age2 = Integer.parseInt(Z2.getStreet());
if (age1 > age2)
{
return 0;
}
else
{
return -1;
}
}
}
public class ZoneDTO {
// 名称
private String name;
private String street;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
}
Result为list< ZoneDTO >
ZoneComparatorName pComparatorStreet = new ZoneComparatorName();
Collections.sort(result, pComparatorStreet);
标签:java
原文地址:http://tianjian.blog.51cto.com/3549910/1665999