Count Reoccurring Characters
Hi guys I'm a little stuck with this so any suggestions would be great.
My goal is to analyze a character arraylist such as xxxxxxaaaa and then turn it into x6a4. This means basically for every time a character repeats it counts it and then prints the character and how many times in a row it repeats.
Here's how I think I can do however I don't feel like this is the best way to accomplish it. If anyone could provide suggestions to do it more efficiently that would be great.
I'll have a for loop which will continue until it has reached the size of the initial arraylist. I have a counter variable to keep track of the number of times the character appears so far.
It then has an if statement to compare the current element in the array list to the previous one. If they match it will increase the counter variable if not it will print the previous character and the total value of the counter variable. It will then set the counter variable back to zero.
Any suggestions on how to improve? Thanks in advance.