Write a Java program which prints number of occurrences of each characters and also it should not print repeatedly occurrences of duplicate characters as given in the example:
Input : geeksforgeeks Output : Number of Occurrence of g is:2 Number of Occurrence of e is:4 Number of Occurrence of k is:2 Number of Occurrence of s is:2 Number of Occurrence of f is:1 Number of Occurrence of o is:1 Number of Occurrence of r is:1
The idea is to create a count array of size 256. Traverse input string and for every character increment its count.
Number of Occurrence of g is:2 Number of Occurrence of e is:4 Number of Occurrence of k is:2 Number of Occurrence of s is:2 Number of Occurrence of f is:1 Number of Occurrence of o is:1 Number of Occurrence of r is:1
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Count occurrences of a given character using Regex in Java
- Java program to count the occurrence of each character in a string using Hashmap
- Find the count of M character words which have at least one character repeated
- Count occurrences of elements of list in Java
- Java program to count the characters in each word in a given sentence
- Pattern Occurrences : Stack Implementation Java
- Remove all occurrences of an element from Array in Java
- Print number of words, vowels and frequency of each character
- Print last character of each word in a string
- Capitalize the first and last character of each word in a string
- Replace all occurrences of a string with space
- Check if a binary string has two consecutive occurrences of one everywhere
- Count occurrence of a given character in a string using Stream API in Java
- Java Program to get a character from a String
- Java Program to convert Character Array to IntStream
- Java.lang.Character Class in Java
- Java.lang.Character.Subset Class in Java
- Java.lang.Character.UnicodeBlock Class in Java
- Program to print ASCII Value of a character
- Program to convert first character uppercase in a sentence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.