Given a string, extract the first letter of each word in it. “Words” are defined as contiguous strings of alphabetic characters i.e. any upper or lower case characters a-z or A-Z.
Input : Geeks for geeks Output :Gfg Input : United Kingdom Output : UK
First letter of each word from string "Geeks for Geeks" : GfG First letter of each word from string "A Computer Science Portal for Geeks" : ACSPfG
Next Article: Extracting each word from a String using Regex in Java
This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Get the first letter of each word in a string using regex in Java
- Extracting each word from a String using Regex in Java
- Check if a string contains only alphabets in Java using Regex
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Java | Removing whitespaces using Regex
- Count occurrences of a given character using Regex in Java
- How to validate an IP address using ReGex
- Java program to count the characters in each word in a given sentence
- Regex Boundary Matchers in Java
- Different Ways to Print First K Characters of the String in Java
- Length Of Last Word in a String
- Remove a given word from a String
- Java program to count the occurrence of each character in a string using Hashmap
- Print number of words, vowels and frequency of each character
- Print all possible ways to convert one string into another string | Edit-Distance
- Check whether two Strings are Anagram of each other using HashMap in Java
- How to find the first and last character of a string in Java
- Remove first and last character of a string in Java
- Swap the first and last character of a string in Java
- Print all unique words of a String