Blogger

Delete comment from: Java67

phil said...

Sorry, but Strings are immutable in Java. This post makes no mention of this extremely important fact. While it is true that the time complexity of the algorithm is O(n) and the space complexity is O(1), both the toCharArray() method and the new String(char[] buffer) constructor make COPIES of their arrays. This example is NOT reversal in place as that's not possible in Java (without unsafe shenanigans) and it does require the use of extra memory (the original String plus at least two array copies.

Jun 1, 2019, 8:33:15 AM


Posted to [Solved] How to reverse a String in place in Java? Example

Google apps
Main menu