java - Insert multiple words to a String issue -
i want insert multiple words in string, offset relative original string:
stringbuffer sb = new stringbuffer("abcdefghijk"); sb.insert(3,"123"); sb.insert(5,"456"); system.out.println(sb);
result:
abc124563defghijk
i'd result is:
abc123de456fghijk
how can do? suggestion.
reverse order of 2 inserts, , you'll expected result. more generally, start larger insertion indices , proceed smaller.
it worth noting stringbuilder
should preferred stringbuffer
.
Comments
Post a Comment