List of usage examples for java.util List add
boolean add(E e);
From source file:JavaCompilerDemo.java
public static void main(String[] args) { String sourceFile = "c:/HelloWorld.Java"; JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null); // prepare the source file(s) to compile List<File> sourceFileList = new ArrayList<File>(); sourceFileList.add(new File(sourceFile)); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromFiles(sourceFileList); CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits); task.run();/*from w w w . j a va2s.c o m*/ boolean result = task.getResult(); if (result) { System.out.println("Compilation was successful"); } else { System.out.println("Compilation failed"); } try { fileManager.close(); } catch (IOException e) { } }
From source file:Main.java
public static void main(String[] args) { // create vector object List<String> vector = new ArrayList<String>(); // populate the vector vector.add("1"); vector.add("2"); vector.add("3"); vector.add("4"); vector.add("from java2s.com"); System.out.println("Before swap: " + vector); // swap the elements Collections.swap(vector, 0, 4); System.out.println("After swap: " + vector); }
From source file:UtilDemo3.java
public static void main(String[] args) { String[] coins = { "A", "B", "C", "D", "E" }; List l = new ArrayList(); for (int i = 0; i < coins.length; i++) l.add(coins[i]); ListIterator liter = l.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); Collections.reverse(l);/* w w w . j av a 2s . c om*/ liter = l.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:Main.java
public static void main(String args[]) { // create linked list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-2); list.add(2);//from w ww. j a v a 2s . co m list.add(-12); list.add(8); // create comparator for reverse order Comparator cmp = Collections.reverseOrder(Collections.reverseOrder()); // sort the list Collections.sort(list, cmp); System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { String[] coins = { "A", "B", "C", "D", "E" }; List src = new LinkedList(); for (int i = 0; i < coins.length; i++) src.add(coins[i]); List dst = new ArrayList(); for (int i = 0; i < coins.length; i++) dst.add(""); Collections.copy(dst, src);/*from www . jav a2 s .c om*/ ListIterator liter = dst.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String storename = args[0];//from www.jav a2 s. c om char[] storepass = args[1].toCharArray(); String alias = args[2]; KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(storename), storepass); java.security.cert.Certificate[] cchain = ks.getCertificateChain(alias); List mylist = new ArrayList(); for (int i = 0; i < cchain.length; i++) { mylist.add(cchain[i]); } CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertPath cp = cf.generateCertPath(mylist); System.out.println(cp); }
From source file:Main.java
public static void main(String args[]) { List<Integer> dataList = new ArrayList<Integer>(); for (int i = 0; i < 10; i++) { dataList.add(i); }//from www.ja v a2s . c om Collections.shuffle(dataList); int[] num = new int[dataList.size()]; for (int i = 0; i < dataList.size(); i++) { num[i] = dataList.get(i); } System.out.println(Arrays.toString(num)); }
From source file:Main.java
public static void main(String[] args) { String[] coins = { "A", "B", "C", "D", "E" }; List src = new LinkedList(); for (int i = 0; i < coins.length; i++) { src.add(coins[i]); }//w w w. j a va 2s .com System.out.println(src); Collections.fill(src, "java2s.com"); Iterator liter = src.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:Main.java
public static void main(String args[]) { // create linked list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-8); list.add(2);/* ww w .j a v a 2s .c o m*/ list.add(-2); list.add(8); // create comparator for reverse order Comparator<Integer> cmp = Collections.reverseOrder(); // sort the list Collections.sort(list, cmp); System.out.println("List sorted in ReverseOrder: "); System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { String string = "var1[value1], var2[value2], var3[value3]"; Pattern pattern = Pattern.compile("(\\[)(.*?)(\\])"); Matcher matcher = pattern.matcher(string); List<String> listMatches = new ArrayList<String>(); while (matcher.find()) { listMatches.add(matcher.group(2)); }/*from ww w. j a va 2 s.c o m*/ for (String s : listMatches) { System.out.println(s); } }