📜  Java中的LinkedBlockingDeque剩余容量()方法

📅  最后修改于: 2022-05-13 01:55:14.057000             🧑  作者: Mango

Java中的LinkedBlockingDeque剩余容量()方法

LinkedBlockingDequeremainingCapacity()方法返回此双端队列理想情况下(在没有内存或资源限制的情况下)可以在不阻塞的情况下接受的附加元素的数量。

句法:

public int remainingCapacity()

参数:此方法不接受任何参数。

返回:此方法返回可插入双端队列容器的剩余元素数。

下面的程序说明了 LinkedBlockingDeque 的剩余容量()方法:

方案一:

// Java Program Demonstrate remainingCapacity()
// method of LinkedBlockingDeque
// when initial size is mentioned
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
        throws InterruptedException
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque LBD
            = new LinkedBlockingDeque(6);
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add(7855642);
        LBD.add(35658786);
        LBD.add(5278367);
        LBD.add(74381793);
  
        // print Dequeue
        System.out.println("Linked Blocking Deque: " + LBD);
        System.out.println("remainingCapacity = : " + 
                              LBD.remainingCapacity());
    }
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
remainingCapacity = : 2

方案二:

// Java Program Demonstrate remainingCapacity()
// method of LinkedBlockingDeque
// when no initial size is mentioned
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
        throws InterruptedException
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque LBD
            = new LinkedBlockingDeque(6);
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add(7855642);
        LBD.add(35658786);
        LBD.add(5278367);
        LBD.add(74381793);
  
        // print Dequeue
        System.out.println("Linked Blocking Deque: " + LBD);
        System.out.println("remainingCapacity = " + 
                             LBD.remainingCapacity());
    }
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
remainingCapacity = 2

参考: https: Java/util/concurrent/LinkedBlockingDeque.html#remainingCapacity–