Java TreeSet add() methodThe add() method of TreeSet class is used to add elements in the set. Add() method stores elements in increasing order. Duplicate elements are not allowed. Syntax:Parameter:e - element to be added in the set Return:It returns true if set does not contain specified element. Example 1Output: TreeSet: [ 1, 2, 5, 8, 10 ] Example 2Output: TreeSet: [ A, B, a, b ] Note: In the Example 2 sorting is done by ASCII value of Characters. As the ASCII value of "A" is 65 and ASCII value of "a" is 97.Example 3Output: TreeSet: [ A, B, a, b ] [ 1, 3, 6, 9 ] Example 4Output: TreeSet: [1, 3, 6, 9, A, B, a, b] Next TopicJava-treeset-ceiling-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