Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

In this page you can find the example usage for java.util ArrayList toArray.

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:io.jari.geenstijl.API.API.java

/**
 * Downloads & parses the articles and images
 *
 * @param force Force download and bypass cache
 * @return Artikel[]/*w  ww  .j  av a2  s . c  o m*/
 * @throws IOException
 * @throws ParseException
 * @throws URISyntaxException
 */
public static Artikel[] getArticles(boolean force, boolean page2, Context context)
        throws IOException, ParseException, URISyntaxException {
    if (!force && !page2) {
        Artikel[] cache = getCache(context);
        if (cache != null)
            return cache;
    }

    domain = context.getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl");

    ensureCookies();

    //we halen onze data van de html versie van geenstijl, omdat de RSS versie pure poep is, en omdat jsoup awesome is
    Document document;
    if (page2)
        document = Jsoup.connect("http://" + domain + "/index2.html").get();
    else
        document = Jsoup.connect("http://" + domain + "/").get();

    Elements artikelen = document.select("#content>article");
    ArrayList<Artikel> resultaat = new ArrayList<Artikel>();
    for (Element artikel_el : artikelen) {
        Artikel artikel = parseArtikel(artikel_el, context);

        resultaat.add(artikel);
    }
    Artikel[] arr_res = new Artikel[resultaat.size()];
    resultaat.toArray(arr_res);
    if (!page2)
        setCache(arr_res, context);
    return arr_res;
}

From source file:com.wakatime.intellij.plugin.WakaTime.java

private static String[] obfuscateKey(String[] cmds) {
    ArrayList<String> newCmds = new ArrayList<String>();
    String lastCmd = "";
    for (String cmd : cmds) {
        if (lastCmd == "--key")
            newCmds.add(obfuscateKey(cmd));
        else/* w w  w . j a v  a  2s  .  c o  m*/
            newCmds.add(cmd);
        lastCmd = cmd;
    }
    return newCmds.toArray(new String[newCmds.size()]);
}

From source file:com.pinterest.secor.util.FileUtil.java

public static String[] listRecursively(String path) throws IOException {
    ArrayList<String> paths = new ArrayList<String>();
    String[] directPaths = list(path);
    for (String directPath : directPaths) {
        if (directPath.equals(path)) {
            assert directPaths.length == 1 : Integer.toString(directPaths.length) + " == 1";
            paths.add(directPath);/*  ww w .  j ava 2 s.c om*/
        } else {
            String[] recursivePaths = listRecursively(directPath);
            paths.addAll(Arrays.asList(recursivePaths));
        }
    }
    return paths.toArray(new String[] {});
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UmlsCommon.LoadRRFToDB.java

private static String[] stringToArray(String string, char token) {
    ArrayList vals = new ArrayList();
    int startPos = 0;
    int endPos = string.indexOf(token);
    while (endPos != -1) {
        vals.add(string.substring(startPos, endPos));
        startPos = endPos + 1;/*from   w w w.  j  a  v a 2  s . com*/
        endPos = string.indexOf(token, startPos);
    }
    vals.add(string.substring(startPos, string.length()));
    return (String[]) vals.toArray(new String[vals.size()]);
}

From source file:net.drgnome.virtualpack.util.Util.java

public static String[][] readIni(InputStream stream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
        ArrayList<String[]> list = new ArrayList<String[]>();
        String line;//from ww  w  .j  a  v  a  2  s . com
        while ((line = reader.readLine()) != null) {
            String[] parts = line.split("=");
            if (parts.length == 2) {
                list.add(parts);
            }
        }
        return list.toArray(new String[0][]);
    }

From source file:morphy.timeseal.TimesealCoder.java

public static byte[][] splitBytes(byte[] bytes, byte splitByte) {
    byte[] bytesToProcess = bytes;

    ArrayList<Byte[]> bytesList = new ArrayList<Byte[]>();
    int idx;//from   ww  w.  j a  v a 2 s.  com
    while ((idx = ArrayUtils.indexOf(bytesToProcess, splitByte)) != -1) {
        bytesList.add(ArrayUtils.toObject(Arrays.copyOfRange(bytesToProcess, 0, idx)));
        if (idx + 1 < bytesToProcess.length) {
            bytesToProcess = Arrays.copyOfRange(bytesToProcess, idx + 1, bytesToProcess.length);
        }
    }
    bytesList.add(ArrayUtils.toObject(bytesToProcess));

    byte[][] newBytes = new byte[bytesList.size()][];
    Byte[][] objBytesArray = bytesList.toArray(new Byte[bytesList.size()][0]);
    for (int i = 0; i < objBytesArray.length; i++) {
        newBytes[i] = ArrayUtils.toPrimitive(objBytesArray[i]);
    }
    return newBytes;
}

From source file:com.galenframework.speclang2.reader.pagespec.ForLoop.java

private static String[] readSequenceFromPageObjects(String sequenceStatement, PageSpecHandler pageSpecHandler) {
    String[] objectPatterns = sequenceStatement.split(",");

    ArrayList<String> matchingObjects = new ArrayList<String>();
    List<String> allObjectNames = pageSpecHandler.getSortedObjectNames();

    for (String objectPattern : objectPatterns) {
        Pattern regex = GalenUtils.convertObjectNameRegex(objectPattern);
        for (String objectName : allObjectNames) {
            if (regex.matcher(objectName).matches()) {
                matchingObjects.add(objectName);
            }/*  w ww .  j  a  v  a  2 s  . c  o  m*/
        }
    }

    Collections.sort(matchingObjects, new AlphanumericComparator());
    return matchingObjects.toArray(new String[] {});
}

From source file:com.wst.cls.HTTPBaseIO.java

public static ArrayList paramToArray(String param) throws UnsupportedEncodingException {
    ArrayList arr = null;//from   w ww.  j  a va  2  s  .co m
    if (param != null) {
        String[] p = param.split("&");
        if (param.toLowerCase().contains("&")) {
            ArrayList p2 = new ArrayList();
            int j = 0;
            for (String p1 : p) {
                if (p1.toLowerCase().startsWith("amp;")) {
                    p2.set(j - 1, p2.get(j - 1) + "&" + p1.substring(4));
                    j--;
                }
                p2.add(p1);
                j++;
            }
            p2.toArray(p);
        }

        for (String p1 : p) {
            String[] item = p1.split("=");
            if (item.length == 2) {
                if (arr == null) {
                    arr = new ArrayList();
                }
                // item[0]=URLDecoder.decode(item[0],charset);
                // item[1]=URLDecoder.decode(item[1],charset);  
                arr.add(item);
            }
        }
    }
    return arr;
}

From source file:adalid.commons.properties.PropertiesHandler.java

public static void printExtendedProperties(ExtendedProperties extendedProperties) {
    ArrayList<String> list = new ArrayList<>();
    for (Iterator i = extendedProperties.getKeys(); i.hasNext();) {
        list.add((String) i.next());
    }/*w  ww .  j a  v  a2 s.co  m*/
    String[] names = new String[list.size()];
    list.toArray(names);
    Arrays.sort(names);
    String[] values;
    for (String name : names) {
        values = extendedProperties.getStringArray(name);
        logger.trace(name + " = "
                + (StringUtils.containsIgnoreCase(name, "password") ? "***" : getArrayString(values)));
    }
}

From source file:com.ikon.module.jcr.stuff.JCRUtils.java

/**
 * Convert a Value array to String array.
 *//* w  w w .j av a2 s  . c  o  m*/
public static String[] rolValue2String(Value[] values)
        throws ValueFormatException, IllegalStateException, javax.jcr.RepositoryException {
    ArrayList<String> list = new ArrayList<String>();

    for (int i = 0; i < values.length; i++) {
        // Do not propagate private openkm roles
        if (!values[i].getString().equals(Config.DEFAULT_ADMIN_ROLE)) {
            list.add(values[i].getString());
        }
    }

    return (String[]) list.toArray(new String[list.size()]);
}