- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 can we print all the capital letters of a given string in Java?
The Character class is a subclass of Object class and it wraps a value of the primitive type char in an object. An object of type Character class contains a single field whose type is char.
We can print all the uppercase letters by iterating the characters of a string in a loop and check individual characters are uppercase letters or not using isUpperCase() method and it is a static method of a Character class.
Syntax
public static boolean isUpperCase(char ch)
Example
public class PrintUpperCaseLetterStringTest { public static void main(String[] args) { String str = "Welcome To Tutorials Point India"; for(int i = 0; i < str.length(); i++) { if(Character.isUpperCase(str.charAt(i))) { System.out.println(str.charAt(i)); } } } }
Output
W T T P I
Advertisements