Java TreeSet pollLast() MethodThe pollLast()method of Java TreeSet class is used to find the largest element and remove it from the set. If the set is empty, it returns null. Syntax:Specified by:pollLast in interface NavigableSet<E> : It is used to find the largest element and remove it from the set, if the set is empty it returns null. Return:It returns the last element of the set, else null if it is empty. Example 1Output: TreeSet: [ 10, 13, 22, 34, 45 ] Removed element using pollLast() : 45 After removing element from TreeSet: [ 10, 13, 22, 34 ] Example 2Output: TreeSet: [A, P, S, g] Removed element using pollLast() : g After removing element from TreeSet: [A, P, S] Example 3Output: TreeSet: [ 2, 3, 5, 7, K, M, V, c ] Removed element using pollLast() : c After removing element from TreeSet: [3, 5, 7, K, M, V] Next TopicJava-treeset-remove-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India