Java program to extract words from a given sentence

Java Programming Language / String in java

5182

Program:

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

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

Output:

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

Explanation:

In this java program, we are going to learn how to extract words from a string? Here, we are reading a string (sentence) and extracting words from it.

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.