Java - Program to find the first non repeated character in a string

Examples

Input - codeforeach , Output - d
Input - principles , Output - r

Pseudo Algorithm

1) Build a map consisting of each character of string with repetition count.
i) Loop through the string characters
ii) For each character,
if the character key is found in the map
increment the value by 1
else
set the value to 1
2) Loop through the map to find the key ( character ) having value 1. If no key has value 1, return null.

Implementation

 

OUTPUT

codeforeach : d

 

 

Submit a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

www.000webhost.com