Java Vector to toIntArray(Vector vect)

Here you can find the source of toIntArray(Vector vect)

Description

Creates a int array from a vector.

License

Open Source License

Parameter

Parameter Description
vect the vector containing the elements

Declaration

public static int[] toIntArray(Vector<Integer> vect) 

Method Source Code

//package com.java2s;
/*/* ww  w.  j a v a  2 s  .  c  o m*/
 * Copyright (C) 1990-2001 DMS Decision Management Systems Ges.m.b.H.
 *
 * This library 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id: Utils.java,v 1.56 2008-11-02 02:01:43 mgordon Exp $
 */

import java.util.*;

public class Main {
    /**
     * Creates a int array from a vector.
     *
     * different from Vector.toArray because casts Integer to int
     *
     * @param   vect        the vector containing the elements
     */
    public static int[] toIntArray(Vector<Integer> vect) {
        if (vect != null && vect.size() > 0) {
            int[] array = new int[vect.size()];

            for (int i = array.length - 1; i >= 0; i--) {
                array[i] = vect.elementAt(i).intValue();
            }

            return array;
        } else {
            return new int[0]; // $$$ static ?
        }
    }
}

Related

  1. toArray(Vector v)
  2. toEnumeration(Vector options)
  3. toHashSet(Vector vector)
  4. toHashSetD(Vector vec)
  5. toIntArray(Vector vec)
  6. toPercent(Vector members, HashMap mapMemberToValue)
  7. vector2doubles(Vector _v)
  8. vectorToColor(float x, float y, float z)
  9. vectorTolatLonDegrees(double X, double Y, double Z)