11. Find Duplicate Characters Count in a String in Java | Java Interview Questions

preview_player
Показать описание
Please use the following link to install the Katalon Studio:

#java #duplicate #charactercount

Рекомендации по теме
Комментарии
Автор

Well explained. I was able to explain in one of interview. Please add your code in comment also

shoaibkolkata
Автор

Very easy solution Krishna !! I see the output is sorted, is that because of the method keySet? Pls let me know.

PRUS
Автор

Awesome solution 👏👍👌! Thanks for this!!

EdClarkHYCT
Автор

New subscriber thanks for this video.please keep up the good work.

MrRowllet
Автор

I tried the below way and it worked

public class DuplicateCharsCountHM {

public static void main(String[] args) {
String str = "Automation Testing";
char[] charArray = str.toCharArray();
Map<Character, Integer> hm = new HashMap<>();
for (Character ch : charArray) {
if (hm.get(ch) != null) {
hm.put(ch, hm.get(ch) + 1);
} else {
hm.put(ch, 1);
}
}
Iterator<Character> iterator = hm.keySet().iterator();
while (iterator.hasNext()) {
Character next = iterator.next();
if (hm.get(next) > 1) {
System.out.println("Count of character " + next + " is: " + hm.get(next));
}
}
}

}

Ajay-mwtv
join shbcf.ru