列表排序常用操作:
1、Model類 implements Comparable<T>
接口
2、Model類 添加接口中 方法
如:
public int compareTo(Object o) {
//bean轉換成Model類相應的BEAN
//Model bean = (Model)o;
if (!this.getAreaName().equals(bean.getAreaName())) {
return this.getAreaName().compareTo(bean.getAreaName());
} else {
if (this.getImsi() > bean.getImsi()) {
return -1;
} else if (this.getImsi() < bean.getImsi()) {
return 1;
} else {
if (this.getMsisdn() > bean.getMsisdn()) {
return -1;
} else if (this.getMsisdn() < bean.getMsisdn()) {
return 1;
} else {
return 0;
}
}
}
}
3、用到List或是Set等列表存儲Model的時候
Collections.sort(list);
如:
List list = new ArratList();
Collections.sort(list);
分享到:
相关推荐
Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作。 10、&和&&的区别。 &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。 11、HashMap...
Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作。 13、&和&&的区别。 &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。 14、...
Collections是针对集合类的帮助类,它提供了一系列针对集合的搜索,排序,线程安全化等操作。 final、finally、finalize的区别? 答:final用于声明属性方法和类,分别表示:属性不可变,方法不可覆盖,类不可继承...
68. Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 15 69. LINUX下线程,GDI类的解释。 15 70. java常用的设计模式?说明工厂模式。 15 71. 内部类可以...
给定一个C语言函数,要求实现在java类中进行调用。 45.如何获得数组的长度? 46.访问修饰符“public/private/protected/缺省的修饰符”的使用 47.用关键字final修饰一个类或者方法时,有何意义? 48.掌握类和...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类型吗? 22 31、String s = "Hello...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类型吗? 22 31、String s = "Hello...
1、一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 2、Java有没有goto? 3、说说&和&&的区别。 4、在JAVA中如何跳出当前的多重嵌套循环? 5、switch语句能否作用在byte上,能否作用在long上...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类吗? 22 31、String s = ...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类吗? 22 31、String s = ...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类型吗? 22 31、String s = ...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类型吗? 22 31、String s = "Hello...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 21 29、super.getClass()方法调用 21 30、String是最基本的数据类型吗? 22 31、String s = "Hello...
28、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 23 29、super.getClass()方法调用 23 30、String是最基本的数据类型吗? 24 31、String s = "Hello...
13.5.1Date类的简单使用404 13.5.2使用SimpleDateFormat格式化输出时间405 13.5.3Calendar类的特色408 13.5.4利用GregorianCalendar输出日历411 13.6Formatter类的使用413 13.6.1Formatter的简单使用413 ...