program to find first duplicate character in java

Write a program to find first repeated character in string and print the duplicate character.

In this find first repeat­ed char­ac­ter in string java pro­gram you have to fol­low below giv­en steps to write this pro­gra.

  1. Split the string val­ue using split() method and store it in String array.
  2. Cal­cu­late the size of String array using length method and store it in size Inte­ger vari­able.
  3. Cre­ate a tem­po­rary vari­able of type int and assign default val­ue 1.
  4. Cre­ate out­er for loop and iter­ate till <size vari­able.
  5. Cre­ate inner for loop and start index i+1 and iter­ate till <size vari­able.
  6. Check the con­di­tion if stringSplit[i].equals(stringSplit[j] con­di­tion is true print the char­ac­ter and then exit the pro­gram using System.exit(0) method. (Read Also : Java word count pro­gram)