Java List Create createSublist(final T[] elements, final Class listImplementation)

Here you can find the source of createSublist(final T[] elements, final Class listImplementation)

Description

create Sublist

License

Apache License

Declaration

private static <T> List<T> createSublist(final T[] elements, final Class<? extends List> listImplementation) 

Method Source Code

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

import java.util.Arrays;
import java.util.List;

public class Main {
    private static <T> List<T> createSublist(final T[] elements, final Class<? extends List> listImplementation) {
        List<T> sublist;/*  w  w w  . j  ava  2 s .c o m*/
        final List<T> asList = Arrays.asList(elements);
        try {
            sublist = listImplementation.newInstance();
            sublist.addAll(asList);
        } catch (final InstantiationException e) {
            sublist = asList;
        } catch (final IllegalAccessException e) {
            sublist = asList;
        }

        return sublist;
    }
}

Related

  1. CreateStringList(Collection values)
  2. createStringList(String csvString)
  3. createStringList(String spaceDelimitedString)
  4. createStringListFromStringArr(String[] stringArr)
  5. createSubList(Collection source, Class type)
  6. createSymbolNameString_From_Parts(List descTagName_Parts)
  7. createTable(List datas, String[] headers, int numColumns, int cellPadding, int border)
  8. createTagList(List tags, String separator)
  9. createTarget(List labels)