Java Code
import java.util.LinkedHashMap; import java.util.Map; public class Test { public static void main(String[] args) { String s = "swiss"; LinkedHashMap<Character,Integer> hm = new LinkedHashMap<>(); for(int i=0;i<s.length();i++) { hm.put(s.charAt(i), hm.getOrDefault(s.charAt(i), 0)+1); } for(Map.Entry<Character, Integer> e : hm.entrySet()) { if(e.getValue() == 1) { System.out.println(e.getKey()); break; } } } }
The above is the detailed content of Find the First Non-Repeated Character in a String. For more information, please follow other related articles on the PHP Chinese website!