Take an empty integer array of \( 256 \) elements to hold the frequency of character of the string.
Iterate through the string and construct the frequency array. Increment the current value of the frequency array by \( 1 \) at the location of the corresponding ASCII value of the character.
Iterate through the string and check the frequency array. Return the first element whose frequency is \( 1 \).
/* When the string is null */ if(string ==null) thrownew NullPointerException(string);
/* Create an empty integer array to store the frequency */ int[] charFrequency =newint[256];
/* Construct the frequency array */ for(int i =0; i < string.length; i++) charFrequency[string.charAt(i)]++;
/* Iterate through string and check the frequency */ for(int i =0; i < string.length; i++){ if(charFrequency[string.charAt(i)]==1) /* Print the first non repeating character */ return string.charAt(i)); break; } }