Zuzuzu-kun Zuzuzu-kun - 25 days ago 6
Android Question

Android Studio:select a particular word in a string of array

I want to select a particular word in my input and put the selected word into array.

EXAMPLE
my input : the quick brown fox
i want to select the Word Quick because it started with letter Q and fox and its started with letter F and put the selected words to array .

I dont have any code right know

Answer Source

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));
}