allocate Direct CharBuffer - Java java.nio

Java examples for java.nio:CharBuffer

Description

allocate Direct CharBuffer

Demo Code


//package com.java2s;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;

public class Main {
    public static void main(String[] argv) throws Exception {
        int size = 2;
        System.out.println(allocateDirectChar(size));
    }//ww  w. jav  a  2s  . co m

    public static CharBuffer allocateDirectChar(int size) {
        ByteBuffer bb = ByteBuffer.allocateDirect(size * 2);
        bb.order(ByteOrder.nativeOrder());
        return bb.asCharBuffer();
    }
}

Related Tutorials