I have two simple examples to support my question. I can't figure out why (1) is working while (2) isn't. In my opinion I use them the same way.
With the second one, I get an type mismatch error that says: Cannot convert from char to string. When I try to find an answer on internet I see the str declared as a var type in all examples. But it works with the first example. So what is the difference in the 'return line' of the code and why is the first working while the second isn't?
The '+' operator is overloaded to do concatenation if one of the arguments to it is a String. Hence str.charAt(str.length()-1) + mid + str.charAt(0) forms a String which is the return type of frontBack() method but str.charAt(0) returns a char which is incompatible return type for the front22() method.