Java LinkedTransferQueue remainingCapacity()方法及示例

Java LinkedTransferQueue remainingCapacity()方法及示例

Java.util.concurrent.LinkedTransferQueue. remainCapacity(): 方法总是返回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<Integer> LTQ
            = new LinkedTransferQueue<Integer>();
 
        // Add numbers to end of LinkedTransferQueue
        LTQ.add(7855642);
        LTQ.add(35658786);
        LTQ.add(5278367);
        LTQ.add(74381793);
 
        // print Deque
        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<String> LTQ
            = new LinkedTransferQueue<String>();
 
        // Add numbers to end of LinkedTransferQueue
        LTQ.add("Geeks");
        LTQ.add("For");
        LTQ.add("Geeks");
        LTQ.add("GeeksForGeeks");
 
        // print Deque
        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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程