Android Iterator to SortedSet Convert sortedSetFromIterator(Iterator i)

Here you can find the source of sortedSetFromIterator(Iterator i)

Description

Constructs a SortedSet<T> with all the elements available from i

License

Open Source License

Parameter

Parameter Description
i an iterator to pull elements from
T < > The type of the elements

Return

a SortedSet of the elements

Declaration

public static <T> SortedSet<T> sortedSetFromIterator(Iterator<T> i) 

Method Source Code

//package com.java2s;

import java.util.Iterator;

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    /**/* w  ww . j  a  v a 2 s  .com*/
     * Constructs a SortedSet&lt;T> with all the elements available from i
     * @param i an iterator to pull elements from
     * @param <T> The type of the elements
     * @return a SortedSet of the elements
     */
    public static <T> SortedSet<T> sortedSetFromIterator(Iterator<T> i) {
        SortedSet<T> retval = new TreeSet<T>();
        while (i.hasNext())
            retval.add(i.next());
        return retval;
    }
}