Sunday , December 11 2016
Home / Blue J / Java program to remove duplicate characters

Java program to remove duplicate characters

Java program to remove duplicate characters or repeated character from a given string.

Example: Thiiis is aa tessstt ssstring
OUTPUT:  This is a test string

Thus our motive is to remove repeated characters or duplicate characters from a given string. This is done by following concept.

Step #1: select the starting character:   ch=str.charAt(0);    (hhhello)
Step #2: Add the character to the resulting/output String: ans = ans + ch;
Step #3: Now until the same character appears skip to add the character in the output string:
while( s.charAt(++i)==ch)
Step #4: Do this uptil i < l ; means for whole length of string.

Program #1:

 OUTPUT:

Program to remove duplicate characters
Java program to remove duplicate/repeated characters from a string

Program #2:  Small change in inner while loop;

 OUTPUT:

Program to remove duplicate characters
Java program to remove duplicate/repeated characters from a string

Incoming terms: Program to remove duplicate or repeated characters from a string.

Also See:   program in Java/ Bluej to display the present date and the date after N days

Check Also

Program for Matrix Multiplication in JAVA

Matrix Multiplication:– Here is given a Java Program for Matrix Multiplication also call matrix product. In ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.