2

I need to send some StringBuilder sb content using a CharBuffer
I was hopping for something like CharBuffer.wrap( sb) but cannot find any elegant way

Before settling for brute force, Is there a neat way to transform StringBuilder into CharBuffer?

1 Answer 1

7

CharBuffer has an append(CharSequence) method. And a StringBuilder is a CharSequence.

So

charBuffer.append(stringBuilder)

UPDATE: Better yet, since CharBuffer.wrap also allows for a CharSequence, in fact your original idea was ok

CharBuffer.wrap(stringBuilder);

should work.

Sign up to request clarification or add additional context in comments.

1 Comment

My Bad for trusting SO more than my own instincts!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.