List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:PlanetSet.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; Collection planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]);// w w w. j a va 2s . co m } String s[] = (String[]) planets.toArray(new String[0]); for (int i = 0, n = s.length; i < n; i++) { System.out.println(s[i]); } planets.remove(names[3]); System.out.println(names[1] + " " + planets.contains(names[1])); System.out.println(names[3] + " " + planets.contains(names[3])); }
From source file:org.biopax.validator.BiopaxValidatorClient.java
/** * Checks BioPAX files using the online BioPAX Validator. * /*from w w w . ja v a 2 s .co m*/ * @see <a href="http://www.biopax.org/validator">BioPAX Validator Webservice</a> * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.err.println("Available parameters: \n" + "<path> <output> [xml|html|biopax] [auto-fix] [only-errors] [maxerrors=n] [notstrict]\n" + "\t- validate a BioPAX file/directory (up to ~25MB in total size, -\n" + "\totherwise, please use the biopax-validator.jar instead)\n" + "\tin the directory using the online BioPAX Validator service\n" + "\t(generates html or xml report, or gets the processed biopax\n" + "\t(cannot fix all errros though) see http://www.biopax.org/validator)"); System.exit(-1); } final String input = argv[0]; final String output = argv[1]; File fileOrDir = new File(input); if (!fileOrDir.canRead()) { System.err.println("Cannot read from " + input); System.exit(-1); } if (output == null || output.isEmpty()) { System.err.println("No output file specified (for the validation report)."); System.exit(-1); } // default options RetFormat outf = RetFormat.HTML; boolean fix = false; Integer maxErrs = null; Behavior level = null; //will report both errors and warnings String profile = null; // match optional arguments for (int i = 2; i < argv.length; i++) { if ("html".equalsIgnoreCase(argv[i])) { outf = RetFormat.HTML; } else if ("xml".equalsIgnoreCase(argv[i])) { outf = RetFormat.XML; } else if ("biopax".equalsIgnoreCase(argv[i])) { outf = RetFormat.OWL; } else if ("auto-fix".equalsIgnoreCase(argv[i])) { fix = true; } else if ("only-errors".equalsIgnoreCase(argv[i])) { level = Behavior.ERROR; } else if ((argv[i]).toLowerCase().startsWith("maxerrors=")) { String num = argv[i].substring(10); maxErrs = Integer.valueOf(num); } else if ("notstrict".equalsIgnoreCase(argv[i])) { profile = "notstrict"; } } // collect files Collection<File> files = new HashSet<File>(); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".owl")); } }; for (String s : fileOrDir.list(filter)) { files.add(new File(fileOrDir.getCanonicalPath() + File.separator + s)); } } else { files.add(fileOrDir); } // upload and validate using the default URL: http://www.biopax.org/biopax-validator/check.html if (!files.isEmpty()) { BiopaxValidatorClient val = new BiopaxValidatorClient(); val.validate(fix, profile, outf, level, maxErrs, null, files.toArray(new File[] {}), new FileOutputStream(output)); } }
From source file:Main.java
public static <T> T[] collectionToArray(Collection<T> l, T[] a) { return l.toArray(a); }
From source file:Main.java
/** Convert a Collection of Strings to a plain array String[]. */ public static String[] unboxStrings(Collection<String> coll) { return coll.toArray(new String[coll.size()]); }
From source file:Main.java
public final static String[] toArray(Collection<String> collection) { return collection.toArray(new String[collection.size()]); }
From source file:Main.java
public static String[] toArray(Collection<String> c) { return c.toArray(new String[c.size()]); }
From source file:Main.java
public static String[] toStringArray(Collection<String> coll) { return coll.toArray(new String[coll.size()]); }
From source file:Main.java
/** * Cast a collection to an array// w w w . j a v a 2s . c o m * * @param collection the collection to cast * @param <T> the type of the collection contents * @return an array of type T */ public static <T> T[] toArray(Collection<T> collection) { return (T[]) collection.toArray(new Object[collection.size()]); }
From source file:Main.java
/** * Converts a Collection containing java.io.File instanced into array * representation. This is to account for the difference between * File.listFiles() and FileUtils.listFiles(). * * @param files a Collection containing java.io.File instances * @return an array of java.io.File/*from w ww . j ava 2s. co m*/ */ public static File[] convertFileCollectionToFileArray(Collection<File> files) { return files.toArray(new File[files.size()]); }
From source file:Main.java
/** * Converts a typed {@link Collection} to a typed array. * /*from w ww . jav a 2 s . c om*/ * @param type * the type class * @param collection * the collection to convert to an array. * @return the array. */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Class<T> type, Collection<T> collection) { return collection.toArray((T[]) Array.newInstance(type, collection.size())); }