What happens if I try to increment an element of a char array in Java?

I am trying to implement the algorithm suggested in the Problem Pseudocode hint in Java. According to the hint, countP and countTW are char arrays. So what happens if I try to increment an element of a char array?
The pseudocode writes (countP[pat.charAt(i)])++ but what happens when that statement is executed? I tried using debugger and print statements to print the char array values. But none of them showed or printed anything. If I try to compare the array values then comparison works fine. So what happens when I try to increment or decrement char array values?

Hey @Varshit07 ,

The pseudocode suggests us to store the character frequency of pattern in countP, and then we choose all windows of size M (size of the pattern) from left to right on the given text, we try to compare it’s character frequency (stored in countTW) with that of pattern. If the frequencies are same, then we can say this window is an anagram of the pattern.

Now, (countP[pat.charAt(i)])++ statement signifies that we’re incrementing the frequency of pat[i], e.g, if we have to store the frequency of pat = “cabc”, countP will look like
{ ‘a’: 1, ‘b’: 1, ‘c’: 2 } - before iterating on pat
{ ‘c’: 1 } - at i=0
{ ‘a’: 1, ‘c’: 1 } - at i=1
{ ‘a’: 1, ‘b’: 1, ‘c’: 1 } - at i=2
{ ‘a’: 1, ‘b’: 1, ‘c’: 2 } - at i=3

Same goes with decrementing.

Hey @vikas.pandey,

I understand what you are getting at. But if we are storing the frequency of characters then does not having an int[] make more sense than having a char[] as mentioned in the problem pseudocode hint?

@Varshit07 yes you’re right. It should be int[]. Updated. Thanks for pointing it out.
Apart from that, I hope you got the logic and were able to solve the problem

Thanks @vikas.pandey. I am able to understand the logic.

Closing this topic as your issue has been resolved by the community. If not Kindly un-mark the accepted solution to re-open the topic or feel free to create a new topic and post a link to this topic as a reference.