I started learning Java yesterday and have no prior programming experience. I'm doing some practice problems before class starts tomorrow so I can get a better understanding of it. The practice problems asks to return the most commonly repeated character from a given list.
I am not sure what I am doing wrong, but the error I get is: String index out of range: 4
Huh... Despite several years experience with java and many years with coding in general I have this mistake while copy-pasting for-loops (either putting "j" where "i" should be, or putting "++" in the down-counting loop) at least once per month!
And by the way, when posting code in the message, you could select it and click button "Code" above the editing area - this will surround it in the special [ code ] tags so that it is pretty printed / aligned, which is quite usable for longer snippets!
There is a more complicated but better approach to counting which you can find in the Java™ Tutorials. That example counts words, but you should be able to amend it to count letters.
If you actually have a List (rather than a list) you can probably get a Stream out of it, which is a newer Java8 construct, and get the Stream to do your counting but I am not sure at the moment how to do that.
This will take every ounce of my mental strength! All for a tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library