Java – set the size to TreeSet
•
Java
Is there any way to provide size limits for treesets in Java collections, just as we do for arrays?
anArray = new int[10];
Solution
The closest you can get to an existing collection with a capacity limit is BlockingQueue When adding an item to the queue, you can specify a blocking timeout of zero seconds (or very small) to throw an exception when the capacity is exceeded For more details, see BlockingQueue offer()
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码