BufferRead.md 1.4 KB
Newer Older
CSDN-Ada助手's avatar
CSDN-Ada助手 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
# Buffer Read


以下关于 `Buffer` 的使用,正确的是:


## 答案

```java
import java.nio.DoubleBuffer;

public class BufferTest {
    public static void main(String[] args) {
        DoubleBuffer doubleBuffer = DoubleBuffer.allocate(10);
        doubleBuffer.put(12.0);
        doubleBuffer.put(25.0);
        doubleBuffer.flip();
        System.out.println(doubleBuffer.get());
        System.out.println(doubleBuffer.get());
        doubleBuffer.clear();
    }
}
```

## 选项

### A

```java
import java.nio.CharBuffer;

public class BufferTest {
    public static void main(String[] args) {
        CharBuffer charBuffer = CharBuffer.allocate(1);
        charBuffer.put("test");
        charBuffer.flip();
        System.err.println(charBuffer.get());
    }
}
```

### B

```java

import java.nio.IntBuffer;

public class BufferTest {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(1);
        intBuffer.put(25);
        intBuffer.put(12);
        intBuffer.flip();
        System.err.println(intBuffer.get());
        System.err.println(intBuffer.get());
    }
}
```

### C

```java
import java.nio.ByteBuffer;

public class BufferTest {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        byte a = 12;
        byteBuffer.put(a);
        System.err.println(byteBuffer.get());
    }
}
```