Convert object List To Object ArrayList - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Convert object List To Object ArrayList

Demo Code


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

public class Main{
    public static void main(String[] argv){
        List objList = java.util.Arrays.asList("asdf","java2s.com");
        String fieldNames = "java2s.com";
        System.out.println(java.util.Arrays.toString(objListToObjArrayList(objList,fieldNames)));
    }/*from   w ww . j a  v a 2 s .  c  o  m*/
    
    public static <T> List<Object[]> objListToObjArrayList(List<T> objList,
            String... fieldNames) {
        List<Object[]> objArrayList = new ArrayList<Object[]>();
        for (T obj : objList) {
            objArrayList.add(ObjectUtil.objToFieldValueArray(obj,
                    fieldNames));
        }
        return objArrayList;
    }
}

Related Tutorials