public static void main(String[] args) { StringBuffer buf = new StringBuffer("123456789"); int start = 3; int end = 6; buf.replace(start, end, "foobar"); System.out.println(buf); } }