Example usage for java.util Vector copyInto

List of usage examples for java.util Vector copyInto

Introduction

In this page you can find the example usage for java.util Vector copyInto.

Prototype

public synchronized void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this vector into the specified array.

Usage

From source file:Main.java

public static void main(String args[]) {
    Vector<String> v1 = new Vector<String>();
    v1.add("A");/*from w  w w. j av  a 2 s  .c o m*/
    v1.add("B");
    v1.add("C");
    String array[] = new String[v1.size()];
    v1.copyInto(array);

    for (int i = 0; i < array.length; i++) {
        System.out.println(array[i]);
    }
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

    Integer anArray[] = new Integer[4];

    anArray[0] = 100;/*from   w  ww.j a  va  2 s.  com*/
    anArray[1] = 100;
    anArray[2] = 100;
    anArray[3] = 100;

    vec.add(4);
    vec.add(3);
    vec.add(2);
    vec.add(1);

    for (Integer number : anArray) {
        System.out.println("Number = " + number);
    }

    // copy into the array
    vec.copyInto(anArray);

    for (Integer number : anArray) {
        System.out.println("Number = " + number);
    }
}

From source file:Main.java

public static String[] fecthAllTimeZoneIds() {
    Vector<String> v = new Vector<String>();
    String[] ids = TimeZone.getAvailableIDs();
    for (int i = 0; i < ids.length; i++) {
        v.add(ids[i]);/*from www  .  j  a v a 2  s . c  o m*/
    }
    java.util.Collections.sort(v, String.CASE_INSENSITIVE_ORDER);
    v.copyInto(ids);
    v = null;
    return ids;
}

From source file:Main.java

/**
 * Returns string keys in a hashtable as array of string
 *
 * @param ht//from  ww  w.jav  a2s . com
 *            , Hashtable
 * @return , string array with hash keys string
 */
public static synchronized String[] hashtableKeysToArray(Hashtable ht) {
    Vector v = new Vector();
    String[] sa = null;
    int count = 0;

    Enumeration e = ht.keys();
    while (e.hasMoreElements()) {
        String s = (String) e.nextElement();
        v.addElement(s);
        count++;
    }

    sa = new String[count];
    v.copyInto(sa);
    return sa;

}

From source file:com.netscape.cmsutil.util.Utils.java

/**
 * returns an array of strings from a vector of Strings
 * there'll be trouble if the Vector contains something other
 * than just Strings//w  w  w .  ja v  a  2 s .  c  om
 */
public static String[] getStringArrayFromVector(Vector<String> v) {
    String s[] = new String[v.size()];

    v.copyInto(s);
    return s;
}

From source file:Main.java

/**
 * Retrieves the given DOM element's child elements with the specified name.
 * If name is null, all children are retrieved.
 *//*from www . j  ava 2  s .co  m*/
public static Element[] getChildren(final Element el, final String name) {
    final Vector v = new Vector();
    final NodeList nodes = el.getChildNodes();
    final int len = nodes.getLength();
    for (int i = 0; i < len; i++) {
        final Node node = nodes.item(i);
        if (!(node instanceof Element))
            continue;
        final Element e = (Element) node;
        if (name == null || e.getTagName().equals(name))
            v.add(e);
    }
    final Element[] els = new Element[v.size()];
    v.copyInto(els);
    return els;
}

From source file:esg.node.core.Resource.java

@SuppressWarnings("unchecked")
private static String[] split(String str, String delim) {
    // Use a Vector to hold the split strings.
    Vector v = new Vector();

    // Use a StringTokenizer to do the splitting.
    StringTokenizer tokenizer = new StringTokenizer(str, delim);
    while (tokenizer.hasMoreTokens()) {
        v.addElement(tokenizer.nextToken());
    }/*from  w w  w  . ja  v a 2s  .  c o m*/

    String[] ret = new String[v.size()];
    v.copyInto(ret);
    return ret;
}

From source file:com.maverick.http.MultiStatusResponse.java

public static MultiStatusResponse[] createResponse(HttpResponse response) throws IOException {

    if (response.getStatus() != 207) {
        throw new IOException(Messages.getString("MultiStatusResponse.not207")); //$NON-NLS-1$
    }//from  w  w  w .  j  a va  2s  .c  o  m

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int read;
    byte[] buf = new byte[4096];
    while ((read = response.getInputStream().read(buf)) > -1) {
        out.write(buf, 0, read);
    }

    // #ifdef DEBUG
    if (log.isDebugEnabled())
        log.debug(new String(out.toByteArray()));
    // #endif

    try {
        IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        IXMLReader reader = StdXMLReader.stringReader(new String(out.toByteArray(), "UTF8")); //$NON-NLS-1$
        parser.setReader(reader);
        IXMLElement rootElement = (IXMLElement) parser.parse();

        if (!rootElement.getName().equalsIgnoreCase("multistatus")) //$NON-NLS-1$
            throw new IOException(
                    Messages.getString("MultiStatusResponse.invalidDavRootElement") + rootElement.getName()); //$NON-NLS-1$

        // Now process the responses
        Vector children = rootElement.getChildrenNamed("response", rootElement.getNamespace()); //$NON-NLS-1$
        Vector responses = new Vector();

        for (Enumeration e = children.elements(); e.hasMoreElements();) {
            responses.addElement(new MultiStatusResponse((IXMLElement) e.nextElement()));
        }

        MultiStatusResponse[] array = new MultiStatusResponse[responses.size()];
        responses.copyInto(array);
        return array;

    } catch (Exception ex) {
        // #ifdef DEBUG
        log.error(Messages.getString("MultiStatusResponse.failedToProcessMultistatusResponse"), ex); //$NON-NLS-1$
        // #endif
        throw new IOException(ex.getMessage());
    }

}

From source file:Main.java

/**
 * Splits a string into substrings. /*from   ww  w  .j av  a 2 s  . co  m*/
 * @param str The string which is to split.
 * @param delim The delimiter character, for example a space <code>' '</code>.
 * @param trailing The ending which is added as a substring though it wasn't 
 *                 in the <code>str</code>. This parameter is just for the 
 *                 <code>IRCParser</code> class which uses this method to 
 *                 split the <code>middle</code> part into the parameters. 
 *                 But as last parameter always the <code>trailing</code> is 
 *                 added. This is done here because it's the fastest way to 
 *                 do it here.<br />
 *                 If the <code>end</code> is <code>null</code> or 
 *                 <code>""</code>, nothing is appended.
 * @return An array with all substrings.
 * @see #split(String, int)
 */
public static String[] split(String str, int delim, String trailing) {
    Vector items = new Vector(15);
    int last = 0;
    int index = 0;
    int len = str.length();
    while (index < len) {
        if (str.charAt(index) == delim) {
            items.add(str.substring(last, index));
            last = index + 1;
        }
        index++;
    }
    if (last != len)
        items.add(str.substring(last));
    if (trailing != null && trailing.length() != 0)
        items.add(trailing);
    String[] result = new String[items.size()];
    items.copyInto(result);
    return result;
}

From source file:org.hecl.jarhack.JarHack.java

/**
 * The <code>stringsplit</code> method is here because older
 * versions of GCJ don't seem to handle String.split very well.
 *
 * @param in a <code>String</code> value
 * @param split a <code>String</code> value
 * @return a <code>String[]</code> value
 *//*w w w.  j a v  a  2s  .  c o m*/
private static String[] stringsplit(String in, String split) {
    Vector ret = new Vector();
    int fromindex = 0;
    int idx = 0;
    int splitlen = split.length();
    while (true) {
        idx = in.indexOf(split, fromindex);
        if (idx < 0)
            break;
        ret.addElement(in.substring(fromindex, idx));
        fromindex = idx + splitlen;
    }
    ret.addElement(in.substring(fromindex));
    String[] retstr = new String[ret.size()];
    ret.copyInto(retstr);
    return retstr;
}