The problem statement say that we need to identify how many time a character appear in a string. Program : package net.jubiliation.example; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class CharacterFrequencyExample { public static void main(String[] args) { String str = "yweeeeerwwesfsfsfsgsgdgxcbgd"; // convert this String into array of character char[] characterArray = str.toCharArray(); final Map<Character, Integer> charactersMap = new HashMap<>(); // maintain for each loop to traverse through each element for (Character character : characterArray) { if (charactersMap.containsKey(character)) { int count = charactersMap.get(character); count++; charactersMap.put(character, count); } else { charactersMap.put(character, 0); } } // Iterating the map to print the characters and frequency for (Entry<Character, Integer> characterEntry : charactersMap.entrySet()) { Character c
Technology - Marketing - Stocks - Views