當前位置:首頁 » 編程語言 » javaappend

javaappend

發布時間: 2022-08-25 15:39:13

java中log.append怎麼用,什麼意思

log是StringBuffer或者StringBuilder
log.append()就是在字元串後面追加內容
例如:
StringBuilder log=new StringBuilder();
log.append("hello");
System.out.println(log); //輸出hello
log.append("World");
System.out.println(log); //輸出helloWorld

Ⅱ java中append方法有什麼用 builder對象可以代表哪些字元 方法的參數什麼情況下需

java中append方法的作用是追加字元串。
builder對象可以代表任何字元串
字元串都需要加引號。

Ⅲ java append錯誤怎麼解決

這樣吧,我是根據前面同學的思路以生產者-消費者方式完成的一個java小demo。

第一個類:
共享值類。
public class ShareValue {
private int count;
public ShareValue(int count) {
this.count = count;
}
public synchronized void plus() throws InterruptedException {
if (count <= 100) {
++count;
System.out.println("Procer:" + count);
this.notifyAll();
} else {
System.out.println("值超過100,停止增加!");
this.wait();
}
}
public synchronized void minus() throws InterruptedException {
if (count > 0) {
--count;
System.err.println("Consumer:" + count);
this.notifyAll();
} else {
System.out.println("值小或等於0,停止減少!");
this.wait();
}
}
}

第二個類:
生產者類
public class Procer implements Runnable {
private ShareValue value;
public Procer(ShareValue value) {
this.value = value;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
try {
value.plus();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

第三個類:
消費者類
public class Consumer implements Runnable {
private ShareValue value;
public Consumer(ShareValue value) {
this.value = value;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
try {
value.minus();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

第四個:
測試類
public class TestPC {
public static void main(String[] args) {
ShareValue value = new ShareValue(0);
Runnable pr = new Procer(value);
Runnable cr = new Consumer(value);
new Thread(pr).start();
new Thread(cr).start();
}
}

希望對你有所幫助,這只是能初步跑起來,可以觀察運行,後面可以逐步調整。

熱點內容
交易貓買腳本靠譜嗎 發布:2025-07-17 11:32:27 瀏覽:519
伺服器系統盤一般做什麼陣列 發布:2025-07-17 11:16:05 瀏覽:362
如何用c語音實現放射密碼 發布:2025-07-17 11:13:03 瀏覽:734
lol腳本2017 發布:2025-07-17 10:52:18 瀏覽:826
編譯條件有哪些 發布:2025-07-17 10:42:51 瀏覽:333
apache設置靜態內容緩存時間 發布:2025-07-17 10:32:32 瀏覽:294
蘋果6不能緩存的視頻 發布:2025-07-17 10:31:44 瀏覽:404
如何把文件夾共享 發布:2025-07-17 10:23:49 瀏覽:298
linux查看命令大全 發布:2025-07-17 10:21:24 瀏覽:976
安卓應用程序和蘋果手機哪個好 發布:2025-07-17 10:20:43 瀏覽:411