List of usage examples for java.util Arrays asList
@SafeVarargs @SuppressWarnings("varargs") public static <T> List<T> asList(T... a)
From source file:EnumerationIterator1.java
public static void main(String args[]) { String elements[] = { "Java", "Source", "and", "Support", "." }; Vector v = new Vector(Arrays.asList(elements)); Enumeration e = v.elements(); Iterator itor = EnumerationIterator1.iterator(e); while (itor.hasNext()) { System.out.println(itor.next()); }/* w w w . j a va 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); CertificateFactory certFact = CertificateFactory.getInstance("X.509"); CertPath path = certFact.generateCertPath(Arrays.asList(new Certificate[] { cert })); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[] intArray = new int[] { 4, 1, 3, -23 }; Arrays.sort(intArray);/*from www . j a va2 s .c om*/ // [-23, 1, 3, 4] String[] strArray = new String[] { "z", "a", "C" }; Arrays.sort(strArray); // [C, a, z] // Case-insensitive sort Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER); // [a, C, z] // Reverse-order sort Arrays.sort(strArray, Collections.reverseOrder()); // [z, a, C] // Case-insensitive reverse-order sort Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER); Collections.reverse(Arrays.asList(strArray)); // [z, C, a] }
From source file:PreferencesDemo.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(PreferencesDemo.class); prefs.put("Location", "Oz"); prefs.put("Footwear", "Ruby Slippers"); prefs.putInt("Companions", 4); prefs.putBoolean("Are there witches?", true); int usageCount = prefs.getInt("UsageCount", 0); usageCount++;//from ww w .j av a 2 s . c o m prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } // You must always provide a default value: System.out.println("How many companions does Dorothy have? " + prefs.getInt("Companions", 0)); }
From source file:DiagnosticCollectorCompile.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromStrings(Arrays.asList("Foo.java")); JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits);//from w ww .j a v a 2 s . c o m boolean success = task.call(); fileManager.close(); System.out.println("Success: " + success); }
From source file:Company.java
public static void main(String args[]) { Employee emps[] = { new Employee("Finance", "Degree, Debbie"), new Employee("Finance", "Grade, Geri"), new Employee("Finance", "Extent, Ester"), new Employee("Engineering", "Measure, Mary"), new Employee("Engineering", "Amount, Anastasia"), new Employee("Engineering", "Ratio, Ringo"), new Employee("Sales", "Stint, Sarah"), new Employee("Sales", "Pitch, Paula"), new Employee("Support", "Rate, Rhoda"), }; Set set = new TreeSet(Arrays.asList(emps)); System.out.println(set);// w ww . j a v a 2 s.c om Set set2 = new TreeSet(Collections.reverseOrder()); set2.addAll(Arrays.asList(emps)); System.out.println(set2); Set set3 = new TreeSet(new EmpComparator()); for (int i = 0, n = emps.length; i < n; i++) { set3.add(emps[i]); } System.out.println(set3); }
From source file:Main.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromStrings(Arrays.asList("YourFile.java")); Iterable<String> options = Arrays.asList("-d", "classes", "-sourcepath", "src"); JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);//from www . j a v a 2 s . c o m boolean success = task.call(); for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { System.out.println(diagnostic.getCode()); System.out.println(diagnostic.getKind()); System.out.println(diagnostic.getPosition()); System.out.println(diagnostic.getStartPosition()); System.out.println(diagnostic.getEndPosition()); System.out.println(diagnostic.getSource()); System.out.println(diagnostic.getMessage(null)); } fileManager.close(); System.out.println("Success: " + success); }
From source file:EmpComparator.java
public static void main(String args[]) { String names[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer", "Maggie", "Roy" }; // Convert to list List list = new ArrayList(Arrays.asList(names)); // Ensure list sorted Collections.sort(list);//from w ww.j a v a2 s . co m System.out.println("Sorted list: [length: " + list.size() + "]"); System.out.println(list); // Search for element in list int index = Collections.binarySearch(list, "Maggie"); System.out.println("Found Maggie @ " + index); // Search for element not in list index = Collections.binarySearch(list, "Jimbo Jones"); System.out.println("Didn't find Jimbo Jones @ " + index); // Insert int newIndex = -index - 1; list.add(newIndex, "Jimbo Jones"); System.out.println("With Jimbo Jones added: [length: " + list.size() + "]"); System.out.println(list); // Min should be Bart System.out.println(Collections.min(list)); // Max should be Roy System.out.println(Collections.max(list)); Comparator comp = Collections.reverseOrder(); // Reversed Min should be Roy System.out.println(Collections.min(list, comp)); // Reversed Max should be Bart System.out.println(Collections.max(list, comp)); }
From source file:Main.java
public static void main(String args[]) { Employee emps[] = { new Employee("Finance", "Degree, Debbie"), new Employee("Finance", "Grade, Geri"), new Employee("Finance", "Extent, Ester"), new Employee("Engineering", "Measure, Mary"), new Employee("Engineering", "Amount, Anastasia"), new Employee("Engineering", "Ratio, Ringo"), new Employee("Sales", "Stint, Sarah"), new Employee("Sales", "Pitch, Paula"), new Employee("Support", "Rate, Rhoda"), }; SortedSet set = new TreeSet(Arrays.asList(emps)); System.out.println(set);// w ww. j a v a2 s.c om try { Object last = set.last(); boolean first = true; while (true) { if (!first) { System.out.print(", "); } System.out.println(last); last = set.headSet(last).last(); } } catch (NoSuchElementException e) { System.out.println(); } Set subset = set.headSet(emps[4]); subset.add(emps[5]); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Reverse Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 9; i++) { JButton button = new JButton(Integer.toString(i)); frame.add(button);//from w ww. j a va 2 s . c o m } final Container contentPane = frame.getContentPane(); Comparator<Component> comp = new Comparator<Component>() { public int compare(Component c1, Component c2) { Component comps[] = contentPane.getComponents(); List list = Arrays.asList(comps); int first = list.indexOf(c1); int second = list.indexOf(c2); return second - first; } }; FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp); frame.setFocusTraversalPolicy(policy); frame.setSize(300, 200); frame.setVisible(true); }