CharBuffer: flip() : CharBuffer « java.nio « Java by API






CharBuffer: flip()

 


import java.nio.CharBuffer;

/**
 * Buffer fill/drain example. This code uses the simplest means of filling and
 * draining a buffer: one element at a time.
 */
public class Main {
  public static void main(String[] argv) throws Exception {
    CharBuffer buffer = CharBuffer.allocate(100);

    String string = "asdf";

    for (int i = 0; i < string.length(); i++) {
      buffer.put(string.charAt(i));
    }

    buffer.flip();
    drainBuffer(buffer);
    buffer.clear();
  }

  private static void drainBuffer(CharBuffer buffer) {
    while (buffer.hasRemaining()) {
      System.out.print(buffer.get());
    }

    System.out.println("");
  }
}

   
  








Related examples in the same category

1.CharBuffer: allocate(int capacity)
2.CharBuffer: array()
3.CharBuffer: arrayOffset()
4.CharBuffer: capacity()
5.CharBuffer: get()
6.CharBuffer: hasArray()
7.CharBuffer: hasRemaining()
8.CharBuffer: limit()
9.CharBuffer: limit(int newLimit)
10.CharBuffer: position()
11.CharBuffer: put(char c)
12.CharBuffer: put(String str)
13.CharBuffer: slice()
14.CharBuffer: subSequence(int start, int end)
15.CharBuffer: wrap(CharSequence csq)
16.CharBuffer: wrap(char[] array, int offset, int length)