实体对象类 --略 排序类----实现Comparator接口,重写compare方法 package com.tang.list; import java.util.Comparator; public class Mycompera implements Comparator<Student> { @Override public int compare(Student o1, Student o2) { if (o1.getSid() > o2.getSid()
1. Collections.sort public class Test { public static void main(String[] args) throws Exception { CityModel city1 = new CityModel(); city1.setCity_code(1); CityModel city2 = new CityModel(); city2.setCity_code(1); CityModel city3 = new CityModel(); c
更新: 在一次搜索“变量声明在循环体内还是循环体外”问题时,碰见了一个这样的代码,与本文类似,代码如下: Document [] old ......//这是数据源 EntityDocument[] newArray = new EntityDocument[old.length];//自定义的类,为了把Document里数据保留下来避免Document被关联对象关闭而导致无法取出数据. EntityDocument d = new EntityDocument(); for(int i=0;i
参考于 深入理解Java虚拟机 这里介绍HotSpot虚拟机(自带的虚拟机) 1.对象的创建 对于程序员来说,创建对象的方法: User user1 = new User(); User user2 = new User(04, "Tom", 20); 对于虚拟机来说: 1.首先遇到new指令,先去方法区(一块内存,有些人也叫永久代,不过书上说了这种叫法其实不是很准确)检查类有没有加载过了,如果没有,虚拟机去加载,如果加载了,在堆中进行创建. 2.创建对象有两种方法:由虚拟机自己决定,
集合类List存放的数据,默认是按照放入时的顺序存放的,比如依次放入A.B.C,则取得时候,则也是A.B.C的顺序,实际场景中,有时我们需要根据自定义的规则对List中的元素进行排序,该如何实现呢?看下面小例子: import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Test { public static
public class Student { private String name; private int age; private int id; public Student() { super(); } public Student(String name, int age, int id) { super(); this.name = name; this.age = age; this.id = id; } public String getName() { retur
resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found. 代码: String sql="SELECT d.content,c.name AS categoryName FROM news_detail d,news_category c WHERE d.categoryId=c.id"; Object[] params ={}; System.out.println(this.executeQuery(sq