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

Updated on: 24-Nov-2023

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements