I'm always confused with enhanced for loop. I have this example
public class NonRepeatedChar
{
public static void main(String[] args)
{
String str = "javapassion";
int[] count = new int[128];
char[] charArr = str.toLowerCase().toCharArray();
for (char c : charArr)
{
count[c]++;
}
for (char c : charArr)
{
if (count[c] == 1)
{
System.out.println("First Non repeated character is : " + c);
break;
}
}
}
}
So in the above in the first for loop it says count[c]++ , this means a new array count is initialised and value of c is stored while the iterator is incremented ?
count[c]can throw IndexOutOfBoundsExceptions becausecharcan have values from 0 to 0xFFFF (65335) in java.