2012年2月10日金曜日

How Do Identify Elements In Treeset Collection

how do identify elements in treeset collection

TreeSet and ArrayList ~ ERP BASIC

TreeSet implements SortedSet:- This class guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements (see Comparable), or by the comparator provided at set creation time, depending on which constructor is used.
import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetExample {

    public static void main(String[] args) {


        // TreeSet return in ordered elements
        TreeSet ts=new TreeSet();

        ts.add("b");
        ts.add("a");
        ts.add("d");
        ts.add("c");

        // get element in Iterator
        Iterator it=ts.iterator();

        // get descending order of elements
        //Iterator it=ts.descendingIterator();


        while(it.hasNext())
        {
          String value=(String)it.next();

          System.out.println("Value :"+value);
        }
    }
}
Output
TreeSet Value:a
TreeSet Value:b
TreeSet Value:c
TreeSet Value :d
 



These are our most popular posts: how do identify elements in treeset collection

Engineering and Technology: Collection(TreeSet)

Collection(TreeSet). In TreeSet binary tre is used. Duplicate cannot be inserted in the tree. TreeSet implements SortedSet that means ordering is guranteed so any element if it is to be added inside a SortedSet must implement ... read more

Java Program to Demonstrate the TreeSet

SortedSet; import java.util.TreeSet; class SSorted { public static void main(String[] argv) throws Exception { SortedSet set = new TreeSet set.add( set.add( set.add( Iterator it = set.iterator(); while (it.hasNext()) { Object element = it.next(); System.out.println(element); } String[] array = (String[]) set.toArray(new String[set.size()]); } ... Java Program to find Whether Given Year is a Leap Year or not. Following Java Example will Show you that which ... read more

program to Demonstrate methods of Tree Set class

class Treesetdemo { public static void main(String args[]) { TreeSet ts=new TreeSet(); ts.add( ts.add( ts.add( ts.add( ts.add( System.out.println(The Tree set elements are: System.out.println(The size ... read more

Java - TreeSet Example

2, boolean addAll(Collection c) Adds all of the elements in the specified collection to this set. 3, void clear() Removes all of the elements from this set. 4, Object clone() Returns a shallow copy of this TreeSet instance. read more

Related Posts



0 コメント:

コメントを投稿