Java Program to Find the occurrence count of each character in the String using the HashMap

preview_player
Показать описание
This video will help you to write the program to find the occurrence of each character in the given string using the concept of hashmap in java
Рекомендации по теме
Комментарии
Автор

String s ="Java";
HashMap <Character, Integer> h = new HashMap();
char []c = s.toCharArray();
for(Character i: c)
{
if(h.containsKey(i))
{
h.put(i, h.get(i)+1);
}
else
{
h.put(i, 1);
}
}
Set <Character> set = h.keySet();
for(char c2 : set)
{
System.out.println("Char: "+c2+" "+h.get(c2));
}

lesterdelacruz
Автор

This has helped me very much! thank you friend.

maniyaa_
Автор

hey i need to use the same concept of just instead of counting no of occurrences i want to grab there index key values
for ex: string =javais
what that hashmap should look like is {
j:0,
a:1, 3
v:2
and so on...
}

could you help me out

ridhim
Автор

nice video bro !! every line was explained properly

parichaymadnani
Автор

// Easiest Solution
public static void main(String[] args) {

String text = "Sanjay";

HashMap<Character, Integer> hashmap = new HashMap<>();

for(int i=0; i< text.length(); i++)
{
char ch = text.charAt(i);
int count=0;

if(hashmap.containsKey(ch))
{
count = hashmap.get(ch);
}

hashmap.put(ch, ++count);
}

System.out.println(hashmap);

}

SanjaySinghYT
Автор

Sir could you Pleasee guide me how to sort number of frequent words used in pdf document. because i want to learn the most important major words for exam would be very helpful 🙏🏽🙏🏽.

sharma
Автор

can u add the code link so we can use it directly

avs
visit shbcf.ru