How to First Non-Repeating Character of String

In this example, we’ll find the first non-repeating character of string:

Input:
String s = "HHello";

Output:
First non repeat character = e

1. Java

public class FirstNonRepeatingCharacterOfString {
    public static void main(String[] args) {
        String s = "HHello";
        for (Character ch : s.toCharArray()) {
            if (s.indexOf(ch) == s.lastIndexOf(ch)) {
                System.out.println("First non repeat character = " + ch);
                break;
            }
        }
    }
}

Output:

First non repeat character = e

Complete Java Solutions can be found here: Github Link

The complete list can be found here: Practise Programming Questions

2 thoughts on “How to First Non-Repeating Character of String”

  1. I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to design my own blog and would like to know where u got this from. appreciate it

    Reply

Leave a Comment