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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -