Java Iterator copyIterator(Iterator iter)

Here you can find the source of copyIterator(Iterator iter)

Description

Iterator to List

License

Apache License

Parameter

Parameter Description
T a parameter
iter a parameter

Declaration

public static <T> List<T> copyIterator(Iterator<T> iter) 

Method Source Code


//package com.java2s;
/*//from ww  w  .ja  va2 s  .c  o m
 * Copyright 2015 Couchbase, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Iterator to List
     * @param <T>
     * @param iter
     * @return 
     */
    public static <T> List<T> copyIterator(Iterator<T> iter) {

        List<T> copy = new ArrayList<T>();
        while (iter.hasNext())
            copy.add(iter.next());
        return copy;
    }
}

Related

  1. contains(Iterator iterator, String value)
  2. convertToArray(Iterator iter)
  3. convertToList(Iterator iter)
  4. copy(Iterator iterator)
  5. copyIterator(Iterable iterable)
  6. copyOf(Iterator elements)
  7. count(Iterator thingsToCount)
  8. countIterator(Iterator it)
  9. createMap(Iterator iter)