capacity « StringBuffer « Java Data Type Q&A

1. What is the capacity of a StringBuffer?

When I run this code:

StringBuffer name = new StringBuffer("");
System.out.println("Length: " + name.length() + ", capacity: " + name.capacity());
it gives output:
Length: 17, capacity: 33
Obvious length is related to number of ...

2. StringBuffer capacity

3. StringBuffer capacity

4. Is there a maximum capacity for a StringBuffer ?

For that amount of data, you want to use a streaming approach (like some of the examples in your earlier thread) rather than trying to buffer all the data (unless you're using a regex which requires to match widely separated data, which your examples didn't). For a simple string match, create a state machine and read one char at a time, ...