First Non-Repeating Character in Java: Explanation & Practice
Find the first character that does not repeat
Problem summary
Write a program that finds the first character that appears only once in a string.
Starter code
public class Main {
public static void main(String[] args) {
String text = "programming"; // Test case 1
// Find first non-repeating character
// Print: First unique: <char> OR No unique character
}
}Expected output and test cases
- p is first unique
First unique: p
- First unique in aabbc
First unique: a
- All repeat
No unique character
Hints
- Count occurrence of each character first
- Then find first with count 1
- Can use array of size 26 for counts
Related Strings exercises
Practice all Strings exercises · Run this idea in the Java compiler