Example usage for java.util TreeSet iterator

List of usage examples for java.util TreeSet iterator

Introduction

In this page you can find the example usage for java.util TreeSet iterator.

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this set in ascending order.

Usage

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tree = new TreeSet<Integer>();

    tree.add(12);/*from w  w w .  j  ava  2  s .c om*/
    tree.add(13);
    tree.add(14);
    tree.add(15);
    tree.add(16);
    tree.add(17);

    // getting values less than 15
    TreeSet<Integer> treeheadset = (TreeSet) tree.headSet(15);

    Iterator<Integer> iterator = treeheadset.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);//from  w ww.  j av  a 2  s. c o  m
    treeadd.add(2);
    treeadd.add(3);
    treeadd.add(4);
    treeadd.add(5);
    treeadd.add(6);
    treeadd.add(7);
    treeadd.add(8);

    TreeSet<Integer> treetailset = (TreeSet<Integer>) treeadd.tailSet(4);

    Iterator<Integer> iterator = treetailset.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);//ww  w .  j  a va2 s.c  o m
    treeadd.add(2);
    treeadd.add(3);
    treeadd.add(4);
    treeadd.add(5);
    treeadd.add(6);
    treeadd.add(7);
    treeadd.add(8);

    TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, 7);

    Iterator<Integer> iterator = treesubset.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:UsingFontFactoryPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from   w  ww.j av a 2s.  co m
        PdfWriter.getInstance(document, new FileOutputStream("UsingFontFactoryPDF.pdf"));
        document.open();

        Paragraph p = new Paragraph("Font Families", FontFactory.getFont(FontFactory.HELVETICA, 16f));
        document.add(p);
        FontFactory.registerDirectories();
        TreeSet families = new TreeSet(FontFactory.getRegisteredFamilies());

        for (Iterator i = families.iterator(); i.hasNext();) {
            p = new Paragraph((String) i.next());
            document.add(p);
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    document.close();
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tree = new TreeSet<Integer>();

    tree.add(12);/*from   www . j av a  2s .  c o  m*/
    tree.add(13);
    tree.add(14);

    // cloning tree into clinetree
    TreeSet<Integer> clonetree = (TreeSet) tree.clone();

    // creating iterator
    Iterator<Integer> iterator = clonetree.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);/*from  w  w  w  .j  av a  2s  . co m*/
    treeadd.add(2);
    treeadd.add(3);
    treeadd.add(4);
    treeadd.add(5);
    treeadd.add(6);
    treeadd.add(7);
    treeadd.add(8);

    TreeSet<Integer> treetailsetincl = (TreeSet<Integer>) treeadd.tailSet(5, true);

    Iterator<Integer> iterator = treetailsetincl.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);/*w  w w.  ja  va  2s.  c  om*/
    treeadd.add(2);
    treeadd.add(3);
    treeadd.add(4);
    treeadd.add(5);
    treeadd.add(6);
    treeadd.add(7);
    treeadd.add(8);

    TreeSet<Integer> treesubset = (TreeSet<Integer>) treeadd.subSet(3, true, 7, true);

    Iterator<Integer> iterator = treesubset.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);//from   ww  w . j a  v  a 2s .c o  m
    treeadd.add(13);
    treeadd.add(17);
    treeadd.add(2);

    // creating reverse set
    TreeSet<Integer> treereverse = (TreeSet<Integer>) treeadd.descendingSet();

    // create descending set
    Iterator<Integer> iterator = treereverse.iterator();

    //Tree set data in reverse order
    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tSet = new TreeSet<Integer>();

    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));

    Iterator itr = tSet.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*from   w w w.j av  a  2  s. c  o m*/
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);/* www  .j  av  a2 s .c  o m*/
    treeadd.add(13);
    treeadd.add(17);
    treeadd.add(22);

    Iterator<Integer> iterator = treeadd.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}