Java IntBuffer Create createIntBuffer(int size)

Here you can find the source of createIntBuffer(int size)

Description

Constructs a direct native-order intbuffer with the specified number of elements.

License

Open Source License

Parameter

Parameter Description
size The size, in ints

Return

an IntBuffer

Declaration

public static IntBuffer createIntBuffer(int size) 

Method Source Code


//package com.java2s;

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

import java.nio.IntBuffer;

public class Main {
    /**// w w  w  .  ja v  a 2s.c om
     * Constructs a direct native-order intbuffer with the specified number
     * of elements.
     * 
     * @param size The size, in ints
     * 
     * @return an IntBuffer
     */
    public static IntBuffer createIntBuffer(int size) {
        return (createByteBuffer(size << 2).asIntBuffer());
    }

    /**
     * Constructs a direct native-order intbuffer with the specified number
     * of elements.
     * 
     * @param values the values
     * 
     * @return an IntBuffer
     */
    public static IntBuffer createIntBuffer(int... values) {
        IntBuffer buff = createIntBuffer(values.length);
        buff.put(values);
        buff.flip();

        return (buff);
    }

    /**
     * Constructs a direct native-ordered bytebuffer with the specified size.
     * 
     * @param size The size, in bytes
     * 
     * @return a ByteBuffer
     */
    public static ByteBuffer createByteBuffer(int size) {
        return (ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()));
    }

    /**
     * Constructs a direct native-ordered bytebuffer with the specified size.
     * 
     * @param values the values
     * 
     * @return a ByteBuffer
     */
    public static ByteBuffer createByteBuffer(byte... values) {
        ByteBuffer buff = createByteBuffer(values.length);
        buff.flip();

        return (buff);
    }
}

Related

  1. createIntBuffer(final int... data)
  2. createIntBuffer(final int... data)
  3. createIntBuffer(int capacity)
  4. createIntBuffer(int size)
  5. createIntBuffer(int size)
  6. createIntBuffer(int... data)
  7. createIntBuffer(int[] array)