文字列から特定の単語を削除する方法を理解するのに少し苦労しています。基本的に私は文字列を持っています。文字列内のすべての単語を、配列内にある事前設定された数の単語と比較します。文字列内の単語が事前設定された単語の 1 つと一致する場合、その単語を文字列から削除します。
例として、「テスト文です」という文字列があります。メソッドを実行した後、{"test", "sentence"} という単語を含む配列が必要です。これまでのところ...
編集 基本的に問題は何も変わらないことです、私は {"is", "a", "test", "sentence"} で終わります
private void fillerWords(){
String[] commonWords = {"the","of","to","and","a","in","is","it","you","that","he","was","for","on","are","with","as","i"};
List <String>wordList = new ArrayList<String>(Arrays.asList(commonWords));
//Split words in sentence up by word, put them into array
String s = "is a test sentance";
String[] tArray = s.split(" ");
List <String>list = new ArrayList<String>(Arrays.asList(tArray ));
//take out words
for(int i=0; i<list.size(); i++){
//Check to see if a sentence word is a common word, if so remove word
for(int c=0; c<wordList.size(); c++){
if(wordList.get(c) == list.get(i)){
list.remove(i);
}//end if
}//end for
}//end for
for(int x=0; x<list.size(); x++){
System.out.printf("%s %s \n", x, list.get(x));
}
}
}