Java List from Array asList(Iterator iterator)

Here you can find the source of asList(Iterator iterator)

Description

as List

License

Apache License

Declaration

public static <T> List<T> asList(Iterator<T> iterator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static <T> List<T> asList(Iterator<T> iterator) {
        List<T> list = new ArrayList<T>();

        while (iterator.hasNext())
            list.add(iterator.next());//from   ww  w  . j  a  va 2s . c  o m

        return list;
    }

    public static List<Long> asList(long... ls) {
        List<Long> list = new ArrayList<Long>();

        for (long l : ls)
            list.add(l);

        return list;
    }

    public static List<String> asList(String... ss) {
        List<String> list = new ArrayList<String>();
        Collections.addAll(list, ss);

        return list;
    }
}

Related

  1. asList(int[] values)
  2. asList(Iterable iterable)
  3. asList(Iterable iterable)
  4. asList(Iterable iterable)
  5. asList(Iterable iterable)
  6. asList(List list)
  7. asList(long... array)
  8. asList(Object info)
  9. asList(Object o, Class cls)