Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 375
Narendra Rawat Avatar asked Jun 28 '16 05:06

Narendra Rawat


People also ask

What is the maximum size of StringBuilder in Java?

Here because of parameter as int the maximum capacity that a StringBuilder Class can is reach will be 2147483647 .

How large can a StringBuilder be?

The length is an int so it should hold up to 2GChar (4GB) assuming you have the memory. You are going to use "only" 600MB (300 million @ 2 bytes per character).

What is the space complexity of StringBuilder?

Each time you append the StringBuilder it checks if the builder array is filled, if required copies the contents of original array to new array of increased size. So the space requirement increases linearly with the length of String. Hence the space complexity is O(n) .


1 Answers

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

like image 153
Subhrajyoti Majumder Avatar answered Nov 06 '22 06:11

Subhrajyoti Majumder