How many characters can a Java StringBuilder hold?

Narendra Rawat picture Narendra Rawat · Jun 28, 2016 · Viewed 14.2k times · Source

Does StringBuilder have a limit of characters for maximum capacity in JAVA.

StringBuilder url=new StringBuilder();

stmt = connnection.createStatement();
String sql="SOME QUERY";
rs = stmt.executeQuery(sql);
while(rs.next())
{
    String emailId=rs.getString("USER_EMAIL_ID");
     url.append(emailId);  
}

does StringBuilder variable 'url' have a maximum capacity, or it can hold everything?

Answer

Subhrajyoti Majumder picture Subhrajyoti Majumder · Jun 28, 2016

Yes, it has limitation in capacity of max integer which 2147483647(technically).

StringBuilder internally holds chracters in char[] object, and array has limitation in size. read more about it on other thread