Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Monday, 19 July 2021

How Do You Find The First Non Repeated Character of a String in Java

Find First Non Repeating Character in a String in Java 

Now Here we are going print First non repeated character in String in java through a simple example or java program so that you can understand well.

So let's start a simple java program for find the first non repeated character of a String.

For example, we take a string in  java like String str = "akalsys";

So in above string there is k is a first non repeated character in String.

Java Example for First Non-Repeated Character in String.

class FirstNonRepeatedCharacterInString
{
public static void main(String args[])
{
String str = "akalsys";
for(char ch : str.toCharArray( ))
{
if(str.indexOf(ch) == str.lastIndexOf(ch))
{
System.out.println(ch);
break;
}
}
}
}

Output : k

Above example will you give the k as output.

Here we learned, how to find the first non repeated character in java string with a simple example.

Share:

1 comment:

  1. very very useful article specially for java interviewer because this question is mostly asked in java interviews.

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate