Removing Repeated Letters From A String

Write a program to input a string from the user in lowercase form.

Then remove all the repeated letters from the string and keep only single occurrences of the characters present in the string.

Display the final string formed after the removal of the extra repeated characters.

INPUT: applications
OUTPUT: aplictons

class Repeated{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("String: ");
        String s = br.readLine().toLowerCase();
        String t = "";
        while(s.length() > 0){
            t += s.charAt(0);
            s = s.replace(Character.toString(s.charAt(0)), "");

2 thoughts on “Removing Repeated Letters From A String”

    • We first take one character from the string, place it to the new string, and then replace that character with an empty string.
      This is repeated as long as the original string has characters left in it.

Leave a Reply

%d bloggers like this: