Java Program to remove the duplicate characters from the string






 import java.util.Scanner;


class RemoveDuplicateCharacter
{

public static void main(String[] arg)
{
  //Ask user to inter a string 
Scanner sc = new Scanner(System.in);

System.out.print("Enter String");
String strsc.nextLine();

String str1="";

for(int i=0 ;i<str.length();i++)
{

  //Store one-one character from 'Str' to 'Str1' and replace it by space 
//in the original string 'str'
  if(str.charAt(i)!=' ')
    {
       str1=str1+str.charAt(i);
       str=str.replace(str.charAt(i),' ');
    }
}

  //printing the final string removing all the duplicate characters
    System.out.print(str1);
}
}

Comments

Popular posts from this blog

Java Program to replace vowel with next immediate character alphabetically in a String.

Java Program to count and output the number of double letter sequences that exist in the string.

Java Program to find the minimum and maximum palindrome String in a Sentence