Below program illustrates how to print duplicate characters in given String using Java:
public class DuplicateStringCharacters { public static void main(String[] args) { String str = "SACHINTENDULKAR"; printDuplicateCharacters(str); } private static void printDuplicateCharacters(String str) { Set<Character> set = new HashSet<>(); Set<Character> duplicates = new HashSet<>(); char[] chars = str.toCharArray(); for (char ch : chars) { boolean isAdded = set.add(ch); if (!isAdded) { duplicates.add(ch); } } for (char ch : duplicates) { System.out.print(ch + " "); } } }