CompareBuffer.java

import java.nio.*;
class CompareBuffer {
  public static void main(String[] args) {
    IntBuffer ib1 = IntBuffer.allocate(11);
    for (int i=0; i<ib1.capacity(); i++) {
      ib1.put(i);
    }
    ib1.rewind();
    IntBuffer ib2 = IntBuffer.allocate(10);
    for (int i=0; i<ib2.capacity(); i++) {
      ib2.put(i+1);
    }
    ib2.rewind();
    System.out.println(ib1.compareTo(ib2)); // affiche -1
    ib1.get();
    System.out.println(ib1.compareTo(ib2)); // affiche 0
  }
}