[Solved] Android Studio:select a particular word in a string of array [closed]


You just need to split the message with space ” ” to get all words. After that with for check the words and if the word’s first letter start with Q or F add it to list of string

String message = "the quick brown fox";
String[] ms = message.split(" ");
List<String> selectedWords = new ArrayList<>();

for (int i = 0; i < ms.length; i++) {
    if(ms[i].toLowerCase().startsWith("q") ||
            ms[i].toLowerCase().startsWith("f"))
        selectedWords.add(ms[i]);
}

Now you can read selected words like this

for (int i = 0; i < selectedWords.size(); i++) {
    etSelectedWord.setText(etSelectedWord.getText() + " " + selectedWords.get(i));
}

0

solved Android Studio:select a particular word in a string of array [closed]