 <p>There is no immediate way to do this. I suggest you append each substring to a <code>List</code> or even to a <code>Stack</code>, and pop whatever you don't need out of your data structure. When you are totally sure about what to present in your <code>StringBuilder</code>, start appending to it by running through your <code>Collection</code> and putting each substring into your final <code>StringBuilder</code>.</p>