public class QueryFirst { public static void main(String[] args) { String str = "aabbc"; System.out.println(getFirst(str)); } public static String getFirst(String str){ char c[] = str.toCharArray(); int n[] = new int[c.length]; for (int i = 0; i < c.length; i++) {
for (int j =0; j < c.length; j++) { if(c[j] == c[i]){ n[i]++; } } } int index = -1; for (int i = 0; i < n.length; i++) { if(n[i] == 1){ index = i;break; } } for (int i = 0; i < n.length; i++) { System.out.println(n[i]); } if(index == -1)return null; return String.valueOf(c[index]); } }