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

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

Krishna Sakinala

4 года назад

27,999 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

himanshu bagga
himanshu bagga - 03.08.2022 09:20

Thanks

Ответить
Gautam Bhosale
Gautam Bhosale - 13.06.2022 14:33

Well Explained .

Ответить
John Jada
John Jada - 30.04.2022 14:45

Super 👍

Ответить
Shoaib Akhtar
Shoaib Akhtar - 21.03.2022 19:11

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

Ответить
Aravind Raj
Aravind Raj - 18.07.2021 13:43

Nice explanation sir.

Ответить
pryAnsh
pryAnsh - 05.06.2021 23:20

Thank u so much 🤝🤝

Ответить
Tridipta Pati
Tridipta Pati - 03.05.2021 13:54

Brother ur explanation is superb

Ответить
Jinu Pappachan
Jinu Pappachan - 03.12.2020 18:04

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

Ответить
Ajay
Ajay - 12.11.2020 10:27

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));
}
}
}

}

Ответить
PR2010US
PR2010US - 29.09.2020 11:24

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

Ответить
Ed Clark
Ed Clark - 11.03.2020 13:04

Awesome solution 👏👍👌! Thanks for this!!

Ответить
Pat Angelo
Pat Angelo - 31.01.2020 11:18

How’s it going?! Great channel. You deserve more subscribers, I think you should check SMZeus[.]com! Since I started using it on my other channel I’m getting way more subscribers!

Ответить