아무도 내 코드에 무엇이 잘못되었는지 말해 줄 수 있습니까?자바에서 문자열을 제거하는 단어
removeWords()
함수에 문자열을 전달하려고하는데이 함수는 String
에서 일부 정보를 제거합니다. 예를 들어
내가 전달하는 경우 :
함수가 반환해야
"나는 Headach 되세요"
"Headach"그러나
을, 내 기능이 작동하지 않습니다.
public class WordChosen extends Activity {
private TextView wordsList;
private String symptom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_word_chosen);
//Getting String from VoiceRecognition Activity and displaying it
Intent intent = getIntent();
String wordChosen = intent.getExtras().getString("wordChosen");
//casting the string with TextView to display the result
wordsList = (TextView) findViewById(R.id.wordChosen);
Log.v("Word List:", "+++++"+wordChosen);
//Setting text to be displayed in the textView
removeWords(wordChosen);
Log.v("removewords:", "------- message is displayed");
}
public void removeWords(String wordList)
{
ArrayList<String> stopList = null;
stopList.add("i");
stopList.add("have");
stopList.add("a");
ArrayList<String> result = new ArrayList<String>(Arrays.asList(wordList.split(" ")));
for(int i=0; i<result.size();i++)
{
for(int j=0; j<stopList.size();j++)
{
if (result.get(i).equals(stopList.get(j))) {
break;
}
else {
if(j==stopList.size()-1)
{
wordsList.setText(result.get(i));
}
}
}
}
}
}
을 반환은 무엇입니까? – Prateek
현재 결과는 무엇입니까? – fasteque
문자열을 변경할 수 없습니다. 메서드에서 새 String을 반환해야합니다. – GriffeyDog