Dave's Brain

Browse - Programming Tips - How can I prepend (add at the start) of a StringBuffer?

Date: 2014mar24
Language: Java
Keywords: append

Q.  How can I prepend (add at the start) of a StringBuffer?

A.  Use insert with position zero:

StringBuffer sb = new StringBuffer(); sb.append("World"); sb.insert(0, "Hello "); // <----- prepending

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.