huang3981658
BAN USERpublic class Singleton{
private volatile static Singleton uniqueInstance;
private Singleton(){}
public static Singleton getInstance(){
if(uniqueInstance == null){
synchronized(Singleton.class){
if(uniqueInstance == null){
uniqueInstance = new Singleton();
}
}
}
return uniqueInstance;
}
}
public void firstNon_repeatingChar(String str){
LinkedHashMap<Character, Integer> hashMap = new LinkedHashMap<Character, Integer>();
for(int i = 0; i < str.length(); i++){
Character c = str.charAt(i);
if(hashMap.get(c) != null){
int value = ((Integer)hashMap.get(c)).intValue();
value++;
hashMap.put(c, value);
}else{
hashMap.put(c, 1);
}
}
Iterator it = hashMap.entrySet().iterator();
boolean first = false;
while(it.hasNext()){
Map.Entry map = (Map.Entry)it.next();
if((Integer)map.getValue() == 1){
if(!first){
System.out.println("first non-repeating character is:" + map.getKey());
first = true;
}
}
}
}
The output will be : “I am born new“
- huang3981658 August 07, 2013