Java ByteBuffer get and set char type data

Description

Java ByteBuffer get and set char type data

import java.nio.ByteBuffer;

public class Main {
  public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(100);

    // Put values of different types
    buf.putChar('a');

    // Reset position for reading
    buf.flip();/* www.j a  va  2  s  . c  om*/

    // Retrieve the values
    char c = buf.getChar();
    
    System.out.println(c);
  }
}



PreviousNext

Related