Java List Cast castOrCopyToList(Iterable iterable)

Here you can find the source of castOrCopyToList(Iterable iterable)

Description

cast Or Copy To List

License

Apache License

Declaration

static <E> List<E> castOrCopyToList(Iterable<E> iterable) 

Method Source Code

//package com.java2s;
/*//from   w  ww  .  jav  a 2 s .  c o m
 * Copyright (C) 2009 The Guava Authors
 *
 * 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.*;

public class Main {
    static <E> List<E> castOrCopyToList(Iterable<E> iterable) {
        if (iterable instanceof List) {
            return (List<E>) iterable;
        }
        List<E> list = new ArrayList<E>();
        for (E e : iterable) {
            list.add(e);
        }
        return list;
    }
}

Related

  1. castList(final Object object)
  2. castList(List list, Class clazz)
  3. castListElem(List list, V target)
  4. castListUnchecked(Object list)
  5. castNonNullListParameterTo(String parameterName, List value, Class requiredType)
  6. castTo(final List list, final Class clasz)
  7. castToDocumentList(Object obj)
  8. castToList(U[] array, Class clazz)
  9. castToStringList(Object value)