TreeSet

We will discus about treeSet() method. The treeSet implement the Set interface. we have stored collection of data and data order of element. We have stored date string and Integer value.

TreeSet

We will discus about treeSet() method. The treeSet implement the Set interface. we have stored collection of data and data order of element. We have stored date string and Integer value.

TreeSet

TreeSet

We will discus about treeSet() method. The treeSet implement the Set interface. we have stored collection of data and data order of element. We have stored date string and Integer value. Set interface are many abele method size(), add(), addAll(),iterator(), remove(Object o), clear(), clone(), comparator(),Object toElement), tailSet(Object fromElement).

TreeSet method are:-

  • Size().
  • add().
  • iterator().
  • remove().

Size().Method:-We get a size of collection of data used for size() method and we contain 4 elements size of the treeSet, which can be determined by calling size() method.

add().Method:-We have added the element used for add() method. If same element already exists it will not be stored.

iterator(). Method:-This method returns an iterator elements of the set interface.

remove().Method:- Remove method removes given elements in set interface.

package Collection;

import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetExample {
	public static void main(String[] args) {
		TreeSet example = new TreeSet();
		
		example.add("C");
		example.add("A");
		example.add("D");
		example.add("B");
		example.add("E");
		example.add("G");
		example.add("F");
		example.add("I");
		example.add("J");
		example.remove("I");
		Iterator iterator;
		iterator = example.iterator();

		System.out.println("Tree set string character arrangements are: ");
             while (iterator.hasNext()) {
			System.out.println(iterator.next() + " ");
          }
		System.out.println("Tree Set size: " + example.size());
		
		
	}
}

OutPut:-

Download Source Code