Home Java Jdk6 TreeSet
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

TreeSet

Advertisement
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. 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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 28, 2013

Related Tutorials

Ask Questions?    Discuss: TreeSet  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com