Java program to print first letter of each word?

Here we break the each word from split method and store in an array,after we iterate this word from for loop and store in string,then from CharAt method we find index and print the first letter.

				
					public class FirstLetterEachWord {
	public static void main(String[] args) {
		String s = "learn with javatechnote";
		splitTest(s);
	}

	public static void splitTest(String str) {
		String[] word = str.split(" ");
		for (int i = 0; i < word.length; i++) {
			String t = word[i];
			System.out.println("word is:- " + t + ", First letter :- " + t.charAt(0));
		}
	}
}
				
			

Output :-
word is:- learn with javatechnote,
First letter :- l,w,j

Leave a Comment

Your email address will not be published. Required fields are marked *