Here you can find the source of setString(ByteBuffer buffer, String data)
public static void setString(ByteBuffer buffer, String data)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Array; import java.nio.ByteBuffer; public class Main { public static void setString(ByteBuffer buffer, String data) { assert (null != data); byte[] bytes = data.getBytes(); assert (buffer.capacity() - buffer.position() >= Array.getLength(bytes)); buffer.put(bytes);/*from www .j ava 2s . c om*/ buffer.put((byte) 0); } }