List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.milaboratory.core.io.util.TestUtil.java
public static String[] getAllLines(File file) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); ArrayList<String> list = new ArrayList<>(); String line;/*from w w w .ja va 2 s . com*/ while ((line = reader.readLine()) != null) { list.add(line); } return list.toArray(new String[list.size()]); }
From source file:Main.java
@SuppressWarnings("unchecked") public static String[] split(String str, String splitsign) { int index;/* ww w .ja va 2 s.c o m*/ if (str == null || splitsign == null) return null; ArrayList al = new ArrayList(); while ((index = str.indexOf(splitsign)) != -1) { al.add(str.substring(0, index)); str = str.substring(index + splitsign.length()); } al.add(str); return (String[]) al.toArray(new String[0]); }
From source file:Main.java
/** */// w ww.j ava 2 s.c o m public static String[] getTextElements(List<Element> elements) throws Exception { ArrayList<String> list = new ArrayList<String>(); Iterator<Element> iter = elements.iterator(); while (iter.hasNext()) { String s = iter.next().getFirstChild().getTextContent(); list.add(s); } return list.toArray(new String[0]); }
From source file:net.foxgenesis.helper.SiteReader.java
/** * Get a sites HTML and store it by line * * @param url/*from w w w. j a va2 s . c om*/ * - site url * @return site's HTML by line * @throws IOException */ public static String[] getHTMLLines(URL url) throws IOException { BufferedReader in = getStream(url); ArrayList<String> output = new ArrayList<String>(); String inputLine; while ((inputLine = in.readLine()) != null) output.add(inputLine); in.close(); return output.toArray(new String[] {}); }
From source file:Main.java
/** * Convert a list of Strings from an Interator into an array of Classes (the * Strings are taken as classnames).//from w w w . j a va 2 s.co m * * @param it * A java.util.Iterator pointing to a Collection of Strings * @param cl * The ClassLoader to use * * @return Array of Classes * * @throws ClassNotFoundException * When a class could not be loaded from the specified ClassLoader */ public final static Class<?>[] convertToJavaClasses(Iterator<String> it, ClassLoader cl) throws ClassNotFoundException { ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); while (it.hasNext()) { classes.add(convertToJavaClass(it.next(), cl)); } return classes.toArray(new Class[classes.size()]); }
From source file:Main.java
public static File[] getFilesDirectorio(String nombreDirectorio) { File directorio = new File(nombreDirectorio); File[] files = directorio.listFiles(); ArrayList<File> filtro = new ArrayList<File>(); if (files != null) for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { filtro.add(files[i]);//from w ww. j a v a 2s . c o m } } return filtro.toArray(new File[filtro.size()]); }
From source file:Main.java
static String[] removeWithspaces(String[] values) { ArrayList<String> list = new ArrayList<String>(values.length); for (int i = 0; i < values.length; i++) { if (!values[i].equals("") && !values[i].equals(" ") && !values[i].equals("\t")) list.add(values[i]);/*w w w . j av a 2s. c om*/ } return list.toArray(new String[list.size()]); }
From source file:ArrayConverter.java
public static Object[] getAsList(final Object maybeArray, final Class arrayType) { if (maybeArray == null) { return null; }/*from w ww .java2 s.c om*/ if (maybeArray.getClass().isArray() == false) { return new Object[] { maybeArray }; } final ArrayList list = new ArrayList(); ArrayConverter.addToList(list, maybeArray); final Object o = Array.newInstance(arrayType, list.size()); return list.toArray((Object[]) o); }
From source file:Main.java
/** * A helper method to get a String[] out of a fieldArray * * @param fields R.strings.class.getFields() * @return a String[] with the string ids we need *//*from ww w. j a v a2 s. co m*/ private static String[] getDefinedFonts(Context ctx, Field[] fields) { ArrayList<String> fieldArray = new ArrayList<String>(); for (Field field : fields) { if (field.getName().contains("define_font_")) { fieldArray.add(getStringResourceByName(ctx, field.getName())); } } return fieldArray.toArray(new String[fieldArray.size()]); }
From source file:Main.java
public static <T> T[] asArrayRemoveNulls(Class<T> a_class, T[] values) /* */ {//from w ww . ja v a2 s. co m /* 509 */ArrayList valueList = new ArrayList(values.length); /* 510 */for (Object t : values) /* */ { /* 512 */if (t == null) /* */continue; /* 514 */valueList.add(t); /* */} /* */ /* 517 */return (T[]) valueList.toArray((Object[]) (Object[]) Array.newInstance(a_class, valueList.size())); /* */}