class MyStringBuffer {
//TODO explain: why you would need these data members.
private char[] chars; //character storage.
private int length; //number of characters used
public String toString(){
//TODO
//Hint: just construct a new String from the ‘chars’ data member
//and return this new String – See API online for how create
//new String from char[]
這只是代碼的一部分,我不想發佈整件事情。我只是專注於此,然後在我完全理解時繼續前進。Java StringBuffer問題
1)當他說從'chars'數據成員構造一個新的String
時,他是什麼意思?我很困惑他想要我做什麼。我是否想用char charAt(int index)
做點什麼?或類似的東西:StringBuffer sb = new StringBuffer("test");
?
2)在Java中構造和創建意味着什麼?
作業的目的是學習如何構建一個對象。答案很簡單,如果沒有給你答案,很難給你任何提示。我建議你看看如何用參數創建一個對象。你的問題中有一個例子。 – 2010-10-16 09:46:05
@Peter Lawrey好的謝謝 – CuriousStudent 2010-10-16 09:50:38