

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print the first character of each word in a String in Java?
A String class can be used to represent the character strings, all the string literals in a Java program are implemented as an instance of a String class. The Strings are constants and their values cannot be changed (immutable) once created.
We can print the first character of each word in a string by using the below program
Example
public class FirstCharacterPrintTest { public static void main(String[] args) { String str = "Welcome To Tutorials Point"; char c[] = str.toCharArray(); System.out.println("The first character of each word: "); for (int i=0; i < c.length; i++) { // Logic to implement first character of each word in a string if(c[i] != ' ' && (i == 0 || c[i-1] == ' ')) { System.out.println(c[i]); } } } }
Output
The first character of each word: W T T P
- Related Questions & Answers
- Java Program to Capitalize the first character of each word in a String
- Print first letter of each word in a string in C#
- Print first letter of each word in a string using C# regex
- Java Program to Print first letter of each word using regex
- How to print out the first character of each list in Python?
- How to capitalize the first letter of each word in a string using JavaScript?
- Getting first letter of each word in a String using regex in Java
- How to print the maximum occurred character of a string in Java?
- Find frequency of each word in a string in Java
- Write a Java program to capitalize each word in the string?
- Find the first repeated word in a string in Java
- How to get first letter of each word using regular expression in Java?
- Write a java program to reverse each word in string?
- Write a java program to tOGGLE each word in string?
- How to find the first character of a string in C#?
Advertisements