Last active
June 13, 2021 11:56
-
-
Save Ram-1234/291912a55cfc9441c9a0aee876d53d8d to your computer and use it in GitHub Desktop.
Unique Character In String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* package whatever; // don't place package name! */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
class Ideone | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
Scanner sc=new Scanner(System.in); | |
String string=sc.nextLine(); | |
ArrayList<Character> list=new ArrayList(); | |
HashMap<Character,Integer> map=new HashMap(); | |
for(int i=0;i<string.length();i++){ | |
if(map.containsKey(string.charAt(i))){ | |
map.put(string.charAt(i),map.get(string.charAt(i))+1); | |
}else{ | |
map.put(string.charAt(i), 1); | |
} | |
} | |
System.out.print(map); | |
for(char d : map.keySet()){ | |
if(map.get(d)==1){ | |
list.add(d); | |
} | |
// System.out.print(map.get(d)+" "); | |
} | |
System.out.print(list); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment