Checking for unique charecters in a String using Java

import java.util.HashMap;

//If no addition data structures can be used then we need to comapare each and every charecter with

//all the charectersi in a string

//We can also use the boolean array to check for duplicate charesters in the string

public class uniquestr {

public static void main(String [] args){

String s = “Ishan”;

char[] c = s.toCharArray();

HashMap< Character, Integer> map = new HashMap<Character, Integer>();

for(char i : c){



map.put(i, map.get(i) +1);

System.out.println(“The string contains duplicate charecter ” + i);



map.put(i, 1);





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s