Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traversing through a sentence word by word

How is it possible to traverse through any given sentence word by word? Is there any in-built functions in java? I have no idea how to begin.

like image 782
Suneeta Singh Avatar asked Oct 24 '25 16:10

Suneeta Singh


1 Answers

Something like this:

String sentence = "Your sentence here.";
String[] words = sentence.split("\\s+"); // splits by whitespace
for (String word : words) {
    System.out.println(word);
}
like image 80
jlordo Avatar answered Oct 26 '25 05:10

jlordo