Java中的 LinkedTransferQueue remainingCapacity() 方法及示例
Java.util.concurrent.LinkedTransferQueue.remainingCapacity():方法总是返回 Integer.MAX_VALUE 因为这种队列不受容量限制。
句法
public int remainingCapacity()
参数:该方法不接受任何参数。
返回:此方法仅返回一个值,即Integer.MAX_VALUE 。
下面的示例说明了 LinkedTransferQueue.remainingCapacity() 方法:
示例 1:
// Java program to illustrate
// LinkedTransferQueue.remainingCapacity() method
import java.util.concurrent.LinkedTransferQueue;
class GFG {
public static void main(String args[])
{
// create object of LinkedTransferQueue
// using LinkedTransferQueue() constructor
LinkedTransferQueue LTQ
= new LinkedTransferQueue();
// Add numbers to end of LinkedTransferQueue
LTQ.add(7855642);
LTQ.add(35658786);
LTQ.add(5278367);
LTQ.add(74381793);
// print Dequee
System.out.println("Linked Transfer Queue1: "
+ LTQ);
// print the remaining capacity
// using remainingCapacity() method
System.out.println(LTQ.remainingCapacity());
}
}
输出:
Linked Transfer Queue1: [7855642, 35658786, 5278367, 74381793]
2147483647
示例 2:
// Java program to illustrate
// LinkedTransferQueue.remainingCapacity() method
import java.util.concurrent.LinkedTransferQueue;
class GFG {
public static void main(String args[])
{
// create object of LinkedTransferQueue
// using LinkedTransferQueue() constructor
LinkedTransferQueue LTQ
= new LinkedTransferQueue();
// Add numbers to end of LinkedTransferQueue
LTQ.add("Geeks");
LTQ.add("For");
LTQ.add("Geeks");
LTQ.add("GeeksForGeeks");
// print Dequee
System.out.println("Linked Transfer Queue1: "
+ LTQ);
// print the remaining capacity
// using remainingCapacity() method
System.out.println(LTQ.remainingCapacity());
}
}
输出:
Linked Transfer Queue1: [Geeks, For, Geeks, GeeksForGeeks]
2147483647