El método hasRemaining() de la clase java.nio.Buffer se usa para saber si hay algún elemento entre la posición actual y el límite.
Sintaxis:
public final boolean hasRemaining()
Devoluciones: este método devolverá verdadero si, y solo si, queda al menos un elemento en este búfer.
A continuación se muestran los ejemplos para ilustrar el método hasRemaining() :
Ejemplos 1:
// Java program to demonstrate // hasRemaining() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the ByteBuffer int capacity = 10; // creating object of bytebuffer // and allocating size capacity ByteBuffer bb = ByteBuffer.allocate(capacity); // putting the value in bytebuffer bb.put((byte)10); bb.put((byte)20); bb.rewind(); // Typecast bytebuffer to Buffer Buffer buffer = (Buffer)bb; // checking buffer is backed by array or not boolean isRemain = buffer.hasRemaining(); // checking if else condition if (isRemain) System.out.println("there is at least one " + "element remaining " + "in this buffer"); else System.out.println("there is no " + "element remaining " + "in this buffer"); } }
Producción:
there is at least one element remaining in this buffer
Ejemplos 2:
// Java program to demonstrate // hasRemaining() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the ByteBuffer int capacity = 0; // creating object of bytebuffer // and allocating size capacity ByteBuffer bb = ByteBuffer.allocate(capacity); // Typecast bytebuffer to Buffer Buffer buffer = (Buffer)bb; // checking buffer is backed by array or not boolean isRemain = buffer.hasRemaining(); // checking if else condition if (isRemain) System.out.println("there is at least one " + "element remaining" + " in this buffer"); else System.out.println("there is no " + "element remaining" + " in this buffer"); } }
Producción:
there is no element remaining in this buffer
Referencia: https://docs.oracle.com/javase/9/docs/api/java/nio/Buffer.html#hasRemaining–
Publicación traducida automáticamente
Artículo escrito por RohitPrasad3 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA