![]() |
In Java Programming, we can be able to capitalize the first letter of each word in the given String value by using toUpperCase(), toLowerCase(), and another one is substring() method. These methods are available String class in Java and these methods are useful for our problem. In this article, we will learn how to capitalize the first letter of each word in a String in Java using different methods. Approach to capitalize the first letter of each word in a StringTo capitalize the first letter of each word in a String, first, we have taken one String value then take the first character from each word in the given string then print the result.
Program to capitalize the first letter of each word in a String in Java1. Using split() and substring() methodsBelow is the implementation of split() and substring() methods to capitalize the first letter of each word in a String. Java
Output
Input welcome to horje Output Welcome To Geeksforgeeks Explanation of the Program:
2. Using Java StreamsJava
Output
Input: welcome to horje Output: Welcome To Geeksforgeeks Explanation of the Program:
3. Using StringBuilderIn this Java code, we have taken one string value, after that we have taken first letter of each word and converted it into capitalize then print the result. Java
Output
Original String: welcome to horje Capitalized String: Welcome To Geeksforgeeks Explanation of the Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |