Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

append() and insert()

 
prashantK Singh
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
kidly someone explain me that what is the difference between
append () and insert()
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
append basically appends the text inside a append statement to the current text in a StringBuilder or StrinBuffer.
e.g:- StringBuilder test = new StringBuilder("abc");
test.append("def");
System.out.println(test);

and the result is abcdef

for insert basically it appends the string to the position specified inside the parenthesis.
e.g:- StringBuilder test = new StringBuilder("ac");
test.insert(1,"b");

System.out.println(test);
result is abc. it basically adds the character to the position specified as '1'. the int off set parameter in the insert() is zero based.

hope this helps.

Dinuka Arseculeratne
 
prashantK Singh
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you dinuka
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic