netbeans4.0beta2,手里的工具只有这个可以试试1.5了,1.5的concurrent也很强悍啊,很方便.
package jdk5;
import java.util.*;
import java.util.concurrent.*;
import static test.constants.first;
/** @author zzzhc
*/
public class main {
public static enum firstenum {one,two};
/** creates a new instance of main * */
private main() {
}
static int count = 0;
static object lock = new object();
/**
* @param args the command line arguments
*/
public static void main(string[] args) throws exception{
list<string> list = new arraylist<string>();//泛型
list.add("1");
list.add("first");
list.add("second");
for (string s:list) {//循环
system.out.println(s);
}
vector v = new vector();
v.add(23);//自动装箱
v.add(32);
v.add(680);
for (int i:v) {//自动拆箱
system.out.println(i);
}
hashmap map = new hashmap();
map.put("key1",23);
system.out.println(map.get("key1"));
for (string i:map.keyset()) {
system.out.println(i);
}
system.out.println(first);//静态导入
system.out.printf("%2$s/t%1$d/n",new integer(1),"str");//printf
for (firstenum fe:firstenum.values()) {
system.out.println(fe);
} //并发
executor exec = executors.newfixedthreadpool(5);
for (int i=0;
i<50;
i++) {
exec.execute(new runnable() {
public void run() {
int cur;
synchronized (lock) {
cur = count++;
}
system.out.println(cur+"running...");
try {
thread.sleep(2000);
}catch (exception e) {
e.printstacktrace();
}
system.out.println(cur+"end...");
if (cur==49) {
system.exit(0);//else program can't exit
}
}
});
}
system.out.println("all started");
runtime.getruntime().addshutdownhook(new thread() {
public void run() {
system.out.println("program end.");
}
});
}
}
@interface enum {
}
闽公网安备 35060202000074号