找出第一次出现重复的字符
import java.util.HashMap; public class Solution{ public static Character findRepeatString(String str){ Character repeatString = null; Map<Character,Integer> map = new HashMap<Character,Integer>(); for(int i=0;i<str.length();i++){ if(map.containsKey(str.charAt(i))){ repeatString= str.charAt(i); break; }else{ map.put(str.charAt(i),1); } } return repeatString; }
public static void main(String[] args){ String str ="4det5gtrr'"; System.out.println(findRepeatString(str)); } }