Home >Java >javaTutorial >How can we print all uppercase letters in a given string in Java?

How can we print all uppercase letters in a given string in Java?

PHPz
PHPzforward
2023-09-04 11:33:06895browse

How can we print all uppercase letters in a given string in Java?

The Character class is a subclass of the Object class, which encapsulates the value of the original type char in an object. Objects of class Character contain a single field of type char.

We can print out all the uppercase letters by iterating over the characters of the string in a loop and using the isUpperCase() method to check if a single character is uppercase. The isUpperCase() method is a static method of the 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.<strong>isUpperCase</strong>(str.<strong>charAt</strong>(i))) {
             System.out.println(str.<strong>charAt</strong>(i));
         }
       }
   }
}

Output

W
T
T
P
I

The above is the detailed content of How can we print all uppercase letters in a given string in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete