I’m just curious about this. It strikes me that the behavior of a StringBuilder is functionally (if not technically) the same as a Stream — it’s a bin of data to which other data can be added.
Again, just curious.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Stream is an input and output of binary data.
StringBuilder is means of building up text data.
Beyond that, there’s the issue of state – a StringBuilder just has the current value, with no idea of ‘position’. It allows you to access and mutate data anywhere within it. A stream, on the other hand, is logically a potentially infinite stream of data, with a cursor somewhere in the middle to say where you’ve got to. You generally just read/write forwards, with Seek/Position to skip to a specific part of the data stream.
Try to imagine implementing the Stream API with StringBuilder… it just doesn’t fit. You could sort of do it, but you’d end up with StringReader and StringWriter, basically.