What is the difference between length() and capacity() methods in StringBuilder ?
I can't understand the difference between them , I mean When should i use length() and when should i use capacity() in StringBuilder?
length() returns the length or number of characters currently.. capacity() returns the maximum characters or amount storage available for current object that it can hold.. Defaultly it is 16 on empty StringBuilder.. It will be doubled on exceed in length each time. Use length() to get length of string...
capacity is allocated length is used