Write a Java program to print duplicate characters in String

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";
	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) {
		for (char ch : duplicates) {
			System.out.print(ch + " ");

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.