當前位置:首頁 » 編程語言 » 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();
}
}

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

熱點內容
app什麼情況下找不到伺服器 發布:2025-05-12 15:46:25 瀏覽:714
php跳過if 發布:2025-05-12 15:34:29 瀏覽:467
不定時演算法 發布:2025-05-12 15:30:16 瀏覽:131
c語言延時1ms程序 發布:2025-05-12 15:01:30 瀏覽:166
動物園靈長類動物配置什麼植物 發布:2025-05-12 14:49:59 瀏覽:737
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:150
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:399
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:545
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:632
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:367