I tried to code method that gives first reccuring char but when the string doesn't have any I get this error:
java.lang.ArrayIndexOutOfBoundsException: 3
Code:
static char firstReccuring(char str[]){
HashSet<Character> map = new HashSet<>();
for(int i=0; i<=str.length; i++ ) {
char ch = str[i];
if(map.contains(ch)) {
return ch;
}else {
map.add(ch);
}
}
return '0';
}
public static void main(String[] args) {
String str = "abc";
char[] arr = str.toCharArray();
System.out.println(firstReccuring(arr));
}