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 {
}
本文地址:http://com.8s8s.com/it/it13759.htm