List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:Main.java
public static void main(String[] argv) throws Exception { List drivers = Collections.list(DriverManager.getDrivers()); for (int i = 0; i < drivers.size(); i++) { Driver driver = (Driver) drivers.get(i); String name = driver.getClass().getName(); System.out.println(name); int majorVersion = driver.getMajorVersion(); System.out.println(majorVersion); int minorVersion = driver.getMinorVersion(); System.out.println(minorVersion); boolean isJdbcCompliant = driver.jdbcCompliant(); System.out.println(isJdbcCompliant); }/*from w w w.j av a 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("A");/* w ww . ja v a 2 s. c o m*/ v.add("B"); v.add("D"); v.add("E"); v.add("F"); System.out.println(v); Enumeration e = v.elements(); ArrayList<String> aList = Collections.list(e); System.out.println(aList); }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("A");/*from w ww . j a v a 2 s .c om*/ v.add("B"); v.add("D"); v.add("E"); v.add("F"); System.out.println(v); Enumeration<String> e = v.elements(); ArrayList<String> aList = Collections.list(e); System.out.println(aList); }
From source file:Main.java
public static void main(String args[]) throws SocketException { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { displayInterfaceInformation(netint); }/*from w ww . j ava 2 s .com*/ }
From source file:Utilities.java
public static void main(String[] args) { List list = Arrays.asList("one Two three Four five six one".split(" ")); System.out.println(list);/* w w w .j a v a 2 s . c o m*/ System.out.println("max: " + Collections.max(list)); System.out.println("min: " + Collections.min(list)); AlphabeticComparator comp = new AlphabeticComparator(); System.out.println("max w/ comparator: " + Collections.max(list, comp)); System.out.println("min w/ comparator: " + Collections.min(list, comp)); List sublist = Arrays.asList("Four five six".split(" ")); System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist)); System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist)); Collections.replaceAll(list, "one", "Yo"); System.out.println("replaceAll: " + list); Collections.reverse(list); System.out.println("reverse: " + list); Collections.rotate(list, 3); System.out.println("rotate: " + list); List source = Arrays.asList("in the matrix".split(" ")); Collections.copy(list, source); System.out.println("copy: " + list); Collections.swap(list, 0, list.size() - 1); System.out.println("swap: " + list); Collections.fill(list, "pop"); System.out.println("fill: " + list); List dups = Collections.nCopies(3, "snap"); System.out.println("dups: " + dups); // Getting an old-style Enumeration: Enumeration e = Collections.enumeration(dups); Vector v = new Vector(); while (e.hasMoreElements()) v.addElement(e.nextElement()); // Converting an old-style Vector // to a List via an Enumeration: ArrayList arrayList = Collections.list(v.elements()); System.out.println("arrayList: " + arrayList); }
From source file:org.apache.commons.net.examples.Main.java
/** * Helper application for example classes. * Lists available classes, and provides shorthand invocation. * For example:<br>//from www. j a v a 2 s . com * <code>java -jar commons-net-examples-m.n.jar FTPClientExample -l host user password</code> * * @param args the first argument is used to name the class; remaining arguments * are passed to the target class. * @throws Throwable if an error occurs */ public static void main(String[] args) throws Throwable { final Properties fp = new Properties(); final InputStream ras = Main.class.getResourceAsStream("examples.properties"); if (ras != null) { fp.load(ras); } else { System.err.println("[Cannot find examples.properties file, so aliases cannot be used]"); } if (args.length == 0) { if (Thread.currentThread().getStackTrace().length > 2) { // called by Maven System.out.println("Usage: mvn -q exec:java -Dexec.arguments=<alias or" + " exampleClass>,<exampleClass parameters> (comma-separated, no spaces)"); System.out.println("Or : mvn -q exec:java -Dexec.args=\"<alias" + " or exampleClass> <exampleClass parameters>\" (space separated)"); } else { if (fromJar()) { System.out.println( "Usage: java -jar commons-net-examples-m.n.jar <alias or exampleClass> <exampleClass parameters>"); } else { System.out.println( "Usage: java -cp target/classes examples/Main <alias or exampleClass> <exampleClass parameters>"); } } @SuppressWarnings("unchecked") // property names are Strings List<String> l = (List<String>) Collections.list(fp.propertyNames()); if (l.isEmpty()) { return; } Collections.sort(l); System.out.println("\nAliases and their classes:"); for (String s : l) { System.out.printf("%-25s %s%n", s, fp.getProperty(s)); } return; } String shortName = args[0]; String fullName = fp.getProperty(shortName); if (fullName == null) { fullName = shortName; } fullName = fullName.replace('/', '.'); try { Class<?> clazz = Class.forName(fullName); Method m = clazz.getDeclaredMethod("main", new Class[] { args.getClass() }); String[] args2 = new String[args.length - 1]; System.arraycopy(args, 1, args2, 0, args2.length); try { m.invoke(null, (Object) args2); } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); if (cause != null) { throw cause; } else { throw ite; } } } catch (ClassNotFoundException e) { System.out.println(e); } }
From source file:com.obidea.semantika.cli.Main.java
public static void main(String[] args) { @SuppressWarnings("unchecked") List<Logger> loggers = Collections.list(LogManager.getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); normal(loggers);/*from w w w . ja v a 2 s . c o m*/ try { CommandLineParser parser = new GnuParser(); CommandLine optionLine = parser.parse(sOptions, args); if (optionLine.hasOption(Environment.VERSION)) { printVersion(); System.exit(0); } if (optionLine.hasOption(Environment.HELP)) { printUsage(); System.exit(0); } String operation = determineOperation(args); if (StringUtils.isEmpty(operation)) { printUsage(); } else { setupLoggers(optionLine, loggers); executeOperation(operation, optionLine); } } catch (Exception e) { System.err.println("Unexpected exception:" + e.getMessage()); //$NON-NLS-1$ System.exit(1); } }
From source file:Main.java
public static <T> List<T> toList(Collection<T> c) { return Collections.list(Collections.enumeration(c)); }
From source file:Main.java
public static String getIP() { try {// w w w . j av a 2s. c o m List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String addr1 = addr.getHostAddress().toUpperCase().replaceAll("^/", ""); if (InetAddressUtils.isIPv4Address(addr1)) { return addr1; } } } } } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:Main.java
public static <T> List<T> toList(Enumeration<T> c) { return Collections.list(c); }