find unique characters in a string java

What you will learn here about java

  • find unique characters in a string using java

find the unique characters in a string java is the one of most common java interview question. finding unique characters in a string using java is very easy and that we will see here.

find unique characters in a string using java

Simple program to find unique characters in a string using java is given below


import java.util.LinkedHashSet;

public class unique {

	public static void main(String[] args)
	{
		String name="INFOSYS";
		
		LinkedHashSet set=new LinkedHashSet();
		
		for(int i=0;i<name.length();i++)
		{
			boolean status=	set.contains(name.charAt(i));
			if(!status)
			{
				set.add(name.charAt(i));
			}
		}
		System.out.println(set);
	}

}


OUTPUT

[I, N, F, O, S, Y]

You may also like...