我想從給定字符串中刪除1個特定單詞(「停止」)的所有實例。 我需要首先分割來完成這個字符串從字符串中刪除單詞(使用特定方法時)
這是我到目前爲止有:
public static String telegram(String sentence)
{
String[] words = sentence.split(" ");
for(int i = 0; i < words.length; i++)
{
if(words[i].equals("STOP"))
{
...
}
}
}
我該如何去有關刪除的話嗎? 我試過使用for循環,並用null這個詞做數組元素,但我不確定這是否會工作。
我需要使用方法append(String)和toString(),我不知道如何使用這些。
在此先感謝!
什麼是這種方法將收到的投入一些例子嗎? –
提示提示 - >使用StringBuilder。它有append和toString() – JNL
看起來像作業 –