---
title: "How to find first non repeated character of a given String?"  
description: "How to find first non repeated character of a given String?"  
author: "Ronan Jone"  
published: 2018-02-27  
canonical: https://answers.mindstick.com/qa/35071/how-to-find-first-non-repeated-character-of-a-given-string  
category: "programming"  
reading_time: 1 minute  

---

# How to find first non repeated character of a given String?

## Answers

### Answer by Arti Mishra

**"Code for finding the first non repeating [character](https://yourviews.mindstick.com/view/80860/sanjay-mishra-s-movie-kamyaab-defines-what-a-character-actor-is) of a given [String](https://www.mindstick.com/articles/1717/string-string-builder-and-string-buffer-in-java)"**\
\
class FindNonReaptingCharacter { /* This [method returns](https://www.mindstick.com/forum/12904/main-method-returns-if-submethod-has-stoped-by-return-in-c-sharp) index of the first non-repeating character in a string. If all [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) are repeating then it returns -1 */\
static int firstNonRepeatingCharacter(String str) { int index = -1, i; for (i = 0; i < str.length(); i++) { for(j=0;j<str.length(); i++) { if (str.charAt(i)==str.charAt[j]) { index = i; break; } }} return index; } // Main Method [public](https://yourviews.mindstick.com/view/81438/modi-haters-will-never-like-him-even-if-public-does) [static void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) main (String[] args) { String str = "[mindstick.com](https://answers.mindstick.com/qa/109931/how-much-time-takes-to-approve-article-on-mindstick-com)"; int index = firstNonRepeatingCharacter(str); [System](https://yourviews.mindstick.com/view/87103/allahabad-high-court-bulldozed-the-islamic-madrasa-system-in-up).out.println(index == -1 ? "Either all characters are repeating " : "First non-repeating character is : : " + str.charAt(index)); } } \


---

Original Source: https://answers.mindstick.com/qa/35071/how-to-find-first-non-repeated-character-of-a-given-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
