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






CharBuffer: get()

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

public class Main {
  private static void symmetricScramble(CharBuffer buffer) {
    while (buffer.hasRemaining()) {
      buffer.mark();
      char c1 = buffer.get();
      char c2 = buffer.get();
      buffer.reset();
      buffer.put(c2).put(c1);
    }
  }

  public static void main(String[] args) {
    char[] data = "UsingBuffers".toCharArray();
    ByteBuffer bb = ByteBuffer.allocate(data.length * 2);
    CharBuffer cb = bb.asCharBuffer();
    cb.put(data);
    System.out.println(cb.rewind());
    symmetricScramble(cb);
    System.out.println(cb.rewind());
    symmetricScramble(cb);
    System.out.println(cb.rewind());

  }
}

   
    
  








Related examples in the same category

1.CharBuffer: allocate(int capacity)
2.CharBuffer: array()
3.CharBuffer: arrayOffset()
4.CharBuffer: capacity()
5.CharBuffer: flip()
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)