java集合中对象排序
概述:本示例实现对象按年龄升序 人气升序排序功能 姓名升序 降序排序功能
package ch02;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* @author YaoShiyou 实现对象排序
*
*/
public class Person {
// 姓名
private String name;
// 年龄
private int age;
// 人气
private int hobby;
public Person(String name) {
this.name = name;
}
public Person(String name, int age) {
this(name);
this.age = age;
}
public Person(String name, int age, int hobby) {
this(name, age);
this.hobby = hobby;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHobby() {
return hobby;
}
public void setHobby(int hobby) {
this.hobby = hobby;
}
public static void main(String[] args) {
List<Person> list = new ArrayList<Person>();
list.add(new Person("g1", 18, 122));
list.add(new Person("g2", 17, 244));
list.add(new Person("g3", 45, 243));
list.add(new Person("g4", 9, 67));
list.add(new Person("g5", 98, 2));
System.out.println("排序前---");
for (Person person : list) {
System.out.println(person.getName() + "\t" + person.getAge() + "\t"
+ person.getHobby());
}
// Collections调用sort 方法 参数为
Collections.sort(list, new AgeComparatorAsc());
System.out.println("年龄排序后----");
for (Person person : list) {
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
1.首先看懂官方文档
2.icbc.jar这个jar包一定要要到!这是进行base64加密解密,以及
使用工行证书签名的重要工具类。
3.采取纯Java编码,要确保用对证书,放在D盘根目录下(其他路径亦可)。
4.编写JSP接口页面,字段必须与工行的一一对应。
而且如tranData等字段进行base64加密后或者签名后 必须以"“双引号扩上才 ......
一、
问:org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.254.103", user "postgres",database "postgres", SSL off
答:PostgreSQ数据库为了安全,它不会监听除本地以外的所有连接请求,当用户通过JDBC访问是,就会报一些以上的异常。要解决这个问题 ......
为了实现自定义的log类,能够输出具体的代码行行号,通过使用StackTraceElement对象实现了。
这里指出需要注意的几个问题:
1. 程序中返回的代码行行号,是新建StackTrackElement对象的那一行。
2. 可以通过传参的方法实现输出特定行行号。具体实现见代码。
1/**
2 *
3 */
4package leo.demo ......