javastringbuilderjava-6capacity

How many characters can a Java StringBuilder hold?


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?


Solution

  • 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