Java examples for java.nio:ByteBuffer
ByteBuffer compare To another ByteBuffer
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static int compareTo(ByteBuffer origin, ByteBuffer that) { int n = origin.position() + Math.min(origin.remaining(), that.remaining()); for (int i = origin.position(), j = that.position(); i < n; i++, j++) { byte v1 = origin.get(i); byte v2 = that.get(j); if (v1 == v2) continue; if ((v1 != v1) && (v2 != v2)) // For float and double continue; if (v1 < v2) return -1; return +1; }//ww w . j av a2 s . c om return origin.remaining() - that.remaining(); } }