×

Java Programs

Java Practice

Java program to extract words from a given sentence

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.
Submitted by Preeti Jain, on March 11, 2018

Given a sentence (string) and we have to extract words from a string using java program.

Extract words from a string in java

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

Core Java Example Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.