We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Strings in Java are immutable, so every invocation of .substring(), .replace() , .toUpperCase() or concatenation with + creates a new String object. Thus, I prefer converting a String to character array or use StringBuilder class that encapsulates a mutable buffer and provides a set of methods to operate on it in a meaningful name. In the end, it creates a new String, of course, but it scales well with the number of applied operations.
Java Strings Introduction
You are viewing a single comment's thread. Return to all comments →
Strings in Java are immutable, so every invocation of
.substring(),.replace(),.toUpperCase()or concatenation with+creates a new String object. Thus, I prefer converting a String to character array or useStringBuilderclass that encapsulates a mutable buffer and provides a set of methods to operate on it in a meaningful name. In the end, it creates a new String, of course, but it scales well with the number of applied operations.My solution looks as follows: