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
相关文档:
在Java
虚拟机中,被加载类型的信息都保存在方法区中。这些信息在内存中的组织形式由虚拟机的实现者定义,比如,虚拟机工作在一个“little- endian”
的处理器上,他就可以将信息保存为“little-endian”
格式的,虽然在Java
类文件中他们是以“big-endian”
格式保 存的。设 ......
记得第一次接触闭包的时候,觉得很奇怪,但从字面上很那理解闭包什么玩意,和闭包有的一比的当属控制反转,真正理解了后觉得就平常了。闭包二字其实是很经典的,闭包代码所表现的东西可不就是一个封闭的、自成一体的功能块吗?简单的说,闭包就是在内部定义的方法,拿到外面去使用。经典的javascript闭包形式如下:
Java代 ......
使用Windows操作系统的朋友对Excel(电子表格)一定不会陌生,但是要使用Java语言来操纵Excel文件并不是一件容易的事。在Web应用日益盛行的今天,通过Web来操作Excel文件的需求越来越强烈,目前较为流行的操作是在JSP或Servlet 中创建一个CSV (comma separated values)文件,并将这� ......
跨平台三维图形开发工具包Java 3D
官方主页:https://java3d.dev.java.net/
Java 3D严格遵循“建模-绘制”泛型。场景图(scene graph)的抽象模型被用来组织和维护虚拟场景中的可是对象及其行为。场景图包含了虚拟图形世界的全部信息,Java 3D绘制引擎会对场景图进行自 ......
说到OA系统就会想到发布公告、审批文件、文件管理等等这些功能,,到了开发人员手里就是存储数据、查询数据,往往不停的做重复工作,于是就有了OA表单引擎的设想和构思。用javascript定义表单,用java驱动XML,自动创建、修改数据库。实现对表单的图形化制作,即使是非技术人员也可随意设计出自己构想的表单功能。
JAVA程� ......