Java Program to Extract Words From a Given Sentence

You are currently viewing Java Program to Extract Words From a Given Sentence

Java program to extract words from a given sentence

class ExtractWordFromSentence
{
	public static void main(String args[])
	{
		String str = "My Name Is Preeti Jain";
		String [] words = str.split(" ", 5);

		for (String word : words)
			System.out.println(word);
	}
}

Output

D:\Java Articles>java ExtractWordFromSentence
My
Name
Is
Preeti
Jain

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply