Use toCharArray() Wisely

Photo by Math on Unsplash

When it comes to implement algorithms that deals with strings, I often use two methods in Java String class: charAt() and toCharArray().

They both can perform some of the same functionalities, e.g. loop through each character in a string. Personally I’m a fan of toCharArray() as I can write more compact code and it saves me a lot of typing, especially in more complex logic. Here is a silly example: