Object Ordering java 排序
Object Ordering
A List l may be sorted as follows.
Collections.sort(l);
If the List consists of String elements, it will be sorted into alphabetical order. If it consists of Date elements, it will be sorted into chronological order. How does this happen? String and Date both implement the Comparable interface. Comparable implementations provide a natural ordering for a class, which allows objects of that class to be sorted automatically. The following table summarizes some of the more important Java platform classes that implement Comparable.
Classes Implementing Comparable
ClassNatural Ordering
Byte
Signed numerical
Character
Unsigned numerical
Long
Signed numerical
Integer
Signed numerical
Short
Signed numerical
Double
Signed numerical
Float
Signed numerical
BigInteger
Signed numerical
BigDecimal
Signed numerical
Boolean
Boolean.FALSE < Boolean.TRUE
File
System-dependent lexicographic on path name
String
Lexicographic
Date
Chronological
CollationKey
Locale-specific lexicographic
If you try to sort a list, the elements of which do not implement Comparable, Collections.sort(list) will throw a ClassCastException. Similarly, Collections.sort(list, comparator) will throw a ClassCastException if you try to sort a list whose elements cannot be compared to one another using the comparator. Elements that can be compared to one another are called mutually comparable. Although elements of different types may be mutually comparable, none of the classes listed here permit interclass comparison.
This is all you really need to know about the Comparable interface if you just want to sort lists of comparable elements or to create sorted collections of them. The next section will be of interest to you if you want to implement your own Comparable type.
Writing Your Own Comparable Types
The Comparable interface consists of the following method.
public interface Comparable<T> {
public int compareTo(T o);
}
The compareTo method c
相关文档:
下载 dom4j-1.6.1.jar。
1: package org.zzp.common.xml.dom4j;
2:
3: import java.io.FileWriter;
4: import java.io.IOException;
5: import org.dom4j.Document;
6: import org.dom4j.DocumentHelper;
7: import org.dom4j.Element;
8: import org.dom4j.io.OutputFormat;
9: impor ......
当Java程序创建一个类的实例或者数组时,都在堆中为新的对象分配内存。虚拟机中只有一个堆,所有的线程都共享它。
1、垃圾收集(Garbage Collection)
垃圾收集是释放没有被引用的对象的主要方法。它也可能会为了减少堆的碎片,而移动对象。 ......
MySQL Java 开发套装(服务器,管理工具,JDBC驱动,示例代码)
小更新: 为了减轻负担, 用 MySQL-Front 2.5 来管理, 这个软件无中文问题. 如果以后开源版本HeidiSQL的解决了中文问题, 就用开源的.
下载: http://tomcatmonitor.googlecode.com/files/portable_mysql5.exe 4.02MB (自解压包)
参考文档: MySQL 5 绿色 ......
跨平台三维图形开发工具包Java 3D
官方主页:https://java3d.dev.java.net/
Java 3D严格遵循“建模-绘制”泛型。场景图(scene graph)的抽象模型被用来组织和维护虚拟场景中的可是对象及其行为。场景图包含了虚拟图形世界的全部信息,Java 3D绘制引擎会对场景图进行自 ......