Home > Java > javaTutorial > body text

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

PHPz
Release: 2023-09-04 11:33:06
forward
847 people have browsed it

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)
Copy after login

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));
         }
       }
   }
}
Copy after login

Output

W
T
T
P
I
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template