当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: 假如你有一个 Integer 对象的列表,并且你想使用 Coolections.sort 来对它们进行排序。
 

 

 ·beanshell    »显示摘要«
    摘要: 简介: beanshell是一种脚本语言,一种完全符合java语法的java脚本语言,并且又拥有自己的一些语法和方法,beanshell是一种松散类型的脚本语言(这点和js类似)。 下载地址:http://www.beanshell.org 设置环境 l 把;bsh-xx.jar放到$java_home/jre/lib/ext文件夹下 l unix: export cla......
 ·使用properties类带来的好处    »显示摘要«
    摘要: monday, february 24 2003 3:18 pm 许多开发者抱怨c++不能像java那样绑定properties类。java的properties类内在包含一个文件,该文件用来读写properties类中的属性,可以写成这样形式:=(例如:connecttointernet=use ie)。 使用properties类的好处就是你......


小议局部类
假如你有一个 integer 对象的列表,并且你想使用 coolections.sort 来对它们进行排序.另外,你还要自己指定一个比较器,因为你想按降序而不是升序排列它们.这里有一些代码示例说明了该怎么做: import java.util.*; public class localdemo1 { // 使用实现了 comparator 的匿名类排序. static void sortanon(list list) { collections.sort(list, new comparator() { public int compare( object o1, object o2) { int cc = ((integer)o1).compareto(o2); return (cc 0 ? -1 : 0); } }); } // 使用实现了 comparator 的局部类排序 static void sortlocal(list list) { class mycomparator implements comparator { public int compare( object o1, object o2) { int cc = ((integer)o1).compareto(o2); return (cc 0 ? -1 : 0); } }; collections.sort(list, new mycomparator()); } public static void main(string[] args) { list list1 = new arraylist(); list1.add(new integer(1)); list1.add(new integer(2)); list1.add(new integer(3)); sortanon(list1); system.out.println(list1); list list2 = new arraylist(); list2.add(new integer(1)); list2.add(new integer(2)); list2.add(new integer(3)); sortlocal(list2); system.out.println(list2); } } 这段程序的输出如下: [3, 2, 1] [3, 2, 1] 上列中使用两种不同的方法实现了 comparator 接口.第一种方法使用匿名类,第二种方法使用局部类,二者有何区别: 一点区别是格式上的——匿名类的定义比较简捷,它实际上是下面这个表达式的一部分: comparator c = new comparator() {...}; 与之相反,局部类的定义看起来非常类似于常规的类定义,略为烦琐.
...   下一页
 ·jar clone的版本冲突    »显示摘要«
    摘要: 新版《星球大战》的精髓就是反对“克隆”。幸运的是,我们要谈的不是像电影中那样致命的“克隆”,但是这种“克隆”带来的伤害依然存在。我们要谈的是围绕apache groups xalan和xerces的一系列问题。 克隆 在我们的观点中“克隆”是指包和类,问题是xml和java好像在一个连续改变的状态中。在说明书中建立的xml新特点,必须在某处执行。通常,新特征和旧版......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE