Java List to Array toArray(List list, Object array[], int start, int end)

Here you can find the source of toArray(List list, Object array[], int start, int end)

Description

to Array

License

LGPL

Declaration

public static Object[] toArray(List list, Object array[], int start, int end) 

Method Source Code

//package com.java2s;
/*// w w w .  j a v  a2 s  . c om
Strandz LGPL - an API that matches the user to the data.
Copyright (C) 2007 Chris Murphy
    
Strandz LGPL is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    
    
The authors can be contacted via www.strandz.org
*/

import java.util.List;

public class Main {
    public static Object[] toArray(List list, Object array[], int start, int end) {
        return toArray(list, array, start, end, -1);
    }

    /**
     * Similar to ArrayList.toArray(), but this method will return a range
     * from the passed in list
     *
     * @param list
     * @param array
     */
    public static Object[] toArray(List list, Object array[], int start, int end, int skip) {
        Object[] result = array;
        int j = 0;
        for (int i = start; i <= end; i++, j++) {
            Object o = null;
            if (skip == -1 || i != skip) {
                o = list.get(i);
            }
            result[j] = o;
        }
        //Print.prArray( result, "toArray() result");
        return result;
    }

    /**
     * Similar to ArrayList.toArray(), but this method will return a range
     * from the passed in list
     *
     * @param list
     */
    public static Object[] toArray(List list, int start, int end) {
        int sizeOfResult = start - end + 1;
        Object[] result = toArray(list, new Object[sizeOfResult], start, end);
        return result;
    }
}

Related

  1. toArray(final List list)
  2. toArray(List list)
  3. toArray(List list)
  4. toArray(List list)
  5. toArray(List list)
  6. toArray(List lista)
  7. toArray(List list)
  8. toArray(List data)
  9. toArray(List list)