In this tutorial, I will be sharing what is Pangram in java, examples of Pangram, algorithm, and java program to check if a given String is a Pangram or not.
Read Also: How to Check String contains Special Characters in Java
What is Pangram String in JavaAccording to Wikipedia,
A String is called Pangram if it is using every letter of a given alphabet at least once. In simple words, if a String contains all the 26 letters of English alphabet at least once.Examples of Pangram:
Below are examples of String which are NOT Pangram:
Java Program for Pangram StringBelow is the simple java program for Pangram String.
Input String is NOT Pangram
Algorithm for Pangram String1. Convert all the characters of inputString to lowercase using the toLowerCase() method and replace all the whitespace characters using the replaceAll(String, String) method.
2. Convert inputString to Character array using toCharArray() method. Iterate through the Character array and add each character to the HashSet object.
3. Since Pangram contains all the 26 letters of the English alphabet, so if the size of the HashSet is also 26 then the inputString is Pangram otherwise not.
That's all for today, please mention in comments in case you have any questions related to Java program to check if a String is a Pangram or not.