集册 Java实例教程 创建一个非

创建一个非

欢马劈雪     最近更新时间:2020-01-02 10:19:05

638
在ByteBuffer上创建非字节Java类型缓冲区

import java.nio.ByteBuffer;

import java.nio.CharBuffer;
/**
 from
* 时 代      J a v a   公   众 号 - nowjava.com 
**/

import java.nio.DoubleBuffer;

import java.nio.FloatBuffer;

import java.nio.IntBuffer;

import java.nio.LongBuffer;

import java.nio.ShortBuffer;


public class Main {

  public void myMethod() {

    // Obtain a ByteBuffer; see also Creating a ByteBuffer

    ByteBuffer buf = ByteBuffer.allocate(15);

    // remaining = 15


    // Create a character ByteBuffer

    CharBuffer cbuf = buf.asCharBuffer();

    // remaining = 7


    // Create a short ByteBuffer
    /** 
    来 自 
    n o w j a v a . c o m - 时代Java
    **/

    ShortBuffer sbuf = buf.asShortBuffer();

    // remaining = 7


    // Create an integer ByteBuffer

    IntBuffer ibuf = buf.asIntBuffer();

    // remaining = 3


    // Create a long ByteBuffer

    LongBuffer lbuf = buf.asLongBuffer();

    // remaining = 1


    
展开阅读全文