You have far too much code for such a trivial task... You should ask your teacher for a tutor.
I will give you a clue, though. Think hash.
Longer clue: Implement a hash where the value is the concatenation of all names starting with the same first letter, and where the key is the first letter .