Find Duplicate Characters in a String : Java Code

preview_player
Показать описание
In this tutorial, I have explained how we can find duplicate characters in a string using java.

Code Link:

Programming questions on string:

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

thanks a lot But can we directly use sysout in line 31 in your video like that.

String str = "Sunil Sharma";
HashMap<Character, Integer> map= new LinkedHashMap<>();

for (Character c : str.toCharArray()) {
if(map.containsKey(c)) {
System.out.print(" "+c);
}
else {
map.put(c, 1);
}
}

sunils.
Автор

Presentation of the examples are nice.First example works fine for the String "JavaProgramming" using Hashmap.Using set example set is not working for the string "JavaProgramming".set results are not expected.Please check and confirm.

cloudlearners
Автор

Where is d code putting value in to the set

rangaiahchowdary