2013年9月1日

Java栈的数组实现

摘要: // ALGORITHM 1.1 Pushdown (LIFO) stack (resizing array implementation)import java.util.Iterator;public class ResizingArrayStack implements Iterable { private Item[] a = (Item[]) new Object[1]; private int N = 0; public boolean isEmpty() { return N == 0; } public int size() { return N; } private void 阅读全文

posted @ 2013-09-01 13:48 cssin 阅读(282) 评论(0) 推荐(0)

2011年12月26日

Java的varargs与泛型

摘要: 一个使用了varargs的泛型方法如下1 public static <T> List<T> toList(T... arr)2 {3 List<T> list = new ArrayList<T>();4 for (T t : arr) list.add(t);5 return list;6 }如下调用将产生错误1 List<Object> objs = Test.toList(1, "two");原因在于编译器将无法正确推断类型参数,所以正确的做法是显式指明类型参数1 List<Object> ob 阅读全文

posted @ 2011-12-26 11:09 cssin 阅读(182) 评论(0) 推荐(0)

Java泛型的Boxing & Unboxing

摘要: 先看代码 1 import java.util.*; 2 3 public class Test 4 { 5 public static int sum(List<Integer> ints) 6 { 7 int s = 0; 8 for (int n : ints) 9 s += n;10 return s;11 }12 13 public static Integer sumIntegers(List<Integer> ints)14 {15 Integer s... 阅读全文

posted @ 2011-12-26 10:13 cssin 阅读(382) 评论(0) 推荐(0)

2011年12月25日

Swing BorderFactory类 (一)

摘要: javax.swing.BorderFactory类是直接继承于java.lang.Object类的, 它定义了34个类方法 1 public class BorderFactory extends Object 2 { 3 public static Border createBevelBorder(int type); 4 public static Border createBevelBorder(int type, Color highlight, Color shadow); 5 public static Border createBevelBorder(i... 阅读全文

posted @ 2011-12-25 21:50 cssin 阅读(1540) 评论(0) 推荐(0)

Swing JFrame API 常用方法

摘要: 1. 构造和设置JFrameJFrame()JFrame(String)Create a frame that is initially invisible. TheStringargument provides a title for the frame. To make the frame visible, invokesetVisible(true)on it.void setDefaultCloseOperation(int)int getDefaultCloseOperation()Set or get the operation that occurs when the user 阅读全文

posted @ 2011-12-25 14:14 cssin 阅读(2032) 评论(0) 推荐(0)

2011年12月22日

Java不允许隐藏变量

摘要: 下面的代码在C/C++中合法,但是在Java中非法1 {2 int x = 10;3 {4 int x = 9;5 }6 } 阅读全文

posted @ 2011-12-22 16:47 cssin 阅读(144) 评论(0) 推荐(0)

2011年12月21日

一般而言,移位操作符的处理速度快于算术运算

摘要: 示例代码如下 1 public class Test 2 3 { 4 5 public static void main(String[] args) 6 7 { 8 9 int low = 0;10 int high = 9;11 12 13 14 long startTime = System.currentTimeMillis();15 16 for (int i = 0; i < Integer.MAX_VALUE; ++i)17 {18 19 int tem... 阅读全文

posted @ 2011-12-21 15:36 cssin 阅读(372) 评论(0) 推荐(0)

2011年12月20日

Java >>>, >>, << 操作符

摘要: 十进制正整数转二进制很容易,不做讨论。十进制负整数转二进制如下,假定一十进制负整数 -5:1. 取5的二进制编码:00000000 00000000 00000000 000001012. 取反码:11111111 11111111 11111111 111110103. 再加1:11111111 11111111 11111111 11111011下面是关于Java中 <<<, <<, >> 操作符的示例程序 1 public class Test 2 { 3 public static void main(String[] args) 4 { 5 阅读全文

posted @ 2011-12-20 21:58 cssin 阅读(233) 评论(0) 推荐(0)

导航