// join(["a", "b", "c"]) -> "a and b and c"
String join(List<String> strs) {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String s : strs) {
if (first) first = false;
else sb.append(" and ");
sb.append(s);
}
return sb.toString();
}
Random rand = new Random();
// Between 1 and 6, inclusive
int diceRoll() {
return rand.nextInt(6) + 1;
}
void filter(List<String> list) {
for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
String item = iter.next();
if (...)
iter.remove();
}
}
String reverse(String s) {
return new StringBuilder(s).reverse().toString();
}
void startAThread0() {
new Thread(new MyRunnable()).start();
}
class MyRunnable implements Runnable {
public void run() {
...
}
}
void startAThread1() {
new MyThread().start();
}
class MyThread extends Thread {
public void run() {
...
}
}
void startAThread2() {
new Thread() {
public void run() {
...
}
}.start();
}
void writeStuff() throws IOException {
OutputStream out = new FileOutputStream(...);
try {
out.write(...);
} finally {
out.close();
}
}
void doWithLock(Lock lock) {
lock.acquire();
try {
...
} finally {
lock.release();
}
}
InputStream in = (...);
try {
while (true) {
int b = in.read();
if (b == -1)
break;
(... process b ...)
}
} finally {
in.close();
}
InputStream in = (...);
try {
byte[] buf = new byte[100];
while (true) {
int n = in.read(buf);
if (n == -1)
break;
(... process buf with offset=0 and length=n ...)
}
} finally {
in.close();
}
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(...), "UTF-8"));
try {
while (true) {
String line = in.readLine();
if (line == null)
break;
(... process line ...)
}
} finally {
in.close();
}
PrintWriter out = new PrintWriter(
new OutputStreamWriter(new FileOutputStream(...), "UTF-8"));
try {
out.print("Hello ");
out.print(42);
out.println(" world!");
} finally {
out.close();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有