/** * @author PLA * 在一个字符串中找到第一个只出现一次的字符 */ public static void main(String[] args) { String s = "dtoghohronogddddew"; int judge = find(s); if(judge!=-1) System.out.println(s.charAt(judge)); else System.out.println("There is no number adaptability!"); } private static int find(String s) { // TODO Auto-generated method stub char[] ch = s.toCharArray(); int[] count = new int[26]; for(char c:ch){ count[c-'a']++; } for(int i=0;i<count.length;i++){ if(count[s.charAt(i)-'a']==1){ return i; } } return -1; }