how to split a sentence into words in java code example
Example 1: java how to split a string into letters
public class SplitString{
public static void main(String[] args)
{
String str = "Enlighter";
String[] arr = str.split("");
for(String character : arr)
System.out.print(char);
Example 2: how to get individual words from a string in java
{
public static void main(String args[])
{
String str = "Hey this is Ram";
String [] words = str. split(" ", 3);
for (String word : words)
System. out. println(word);
Example 3: split method in java
public class SplitExample2 {
public static void main(String args[])
{
String str = "My name is Chaitanya";
String[] arr = str.split(" ");
for (String s : arr)
System.out.println(s);
}
}