Java Program to find the Duplicate Characters in a String1 min read

We write a program to find duplicate characters in a string in java. For example, consider a string “nut cutter“, duplicate characters in it are : u: 2, t : 3.

Program Approach:

First, we created a string variable and take the user input for a string to compare with. And initialize a variable num to keep the number of counts. Then we convert the string variable to characters by creating a character array. Then with iteration(for loop), we compare the two characters and if the character of the compared index is matched, then we display that character with the increase of num with each iteration.

The for loop will continue till the length of the entered string is finished.


Java program of string to check duplicate characters.

The output of duplicate characters in java

Enter a string:
simple2code.com
Duplicate characters are:
m
e
c
o


MORE

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …