Check Case Of A Character Example Java Program


Definition

A string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. A string is generally understood as a data type and is often implemented as an array of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. The case of a particular string can be found using inbuilt methods. These methods checks the case of each character in the string.

Syntax

String_Variable_Name.isUppercase()
Or
String_Variable_Name.isLowercase()

Check Case Of A Character Example Program

public class CheckCaseOfCharacter {
	public static void main(String[] args) {
		String characters = "AbCdefGHijklMNOpqRstUVwxyZ@%*765";
		int length = characters.length();
		for(int i = 0; i < length; i++) {
			char character = characters.charAt(i);
			if(Character.isUpperCase(character)) {
				System.out.println("Given character : " + characters.charAt(i)+ " is an Uppercase letter");
			}
			else if(Character.isLowerCase(character)) {
				System.out.println("Given character : " + characters.charAt(i)+ " is a Lowercase letter");
			}
			else {
				System.out.println("Given character : " + characters.charAt(i)+ " is neither Uppercase nor Lowercase letter");
			}
		}
 
	}
}

Sample Output

Output is:
Given character : A is an Uppercase letter
Given character : b is a Lowercase letter
Given character : C is an Uppercase letter
Given character : d is a Lowercase letter
Given character : e is a Lowercase letter
Given character : f is a Lowercase letter
Given character : G is an Uppercase letter
Given character : H is an Uppercase letter
Given character : i is a Lowercase letter
Given character : j is a Lowercase letter
Given character : k is a Lowercase letter
Given character : l is a Lowercase letter
Given character : M is an Uppercase letter
Given character : N is an Uppercase letter
Given character : O is an Uppercase letter
Given character : p is a Lowercase letter
Given character : q is a Lowercase letter
Given character : R is an Uppercase letter
Given character : s is a Lowercase letter
Given character : t is a Lowercase letter
Given character : U is an Uppercase letter
Given character : V is an Uppercase letter
Given character : w is a Lowercase letter
Given character : x is a Lowercase letter
Given character : y is a Lowercase letter
Given character : Z is an Uppercase letter
Given character : @ is neither Uppercase nor Lowercase letter
Given character : % is neither Uppercase nor Lowercase letter
Given character : * is neither Uppercase nor Lowercase letter
Given character : 7 is neither Uppercase nor Lowercase letter
Given character : 6 is neither Uppercase nor Lowercase letter
Given character : 5 is neither Uppercase nor Lowercase letter