List of usage examples for java.util List add
boolean add(E e);
From source file:Main.java
public static void main(String[] args) { // create a new list of arguments for our process List<String> list = new ArrayList<String>(); list.add("notepad.exe"); // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the command list System.out.println(pb.command()); }
From source file:Main.java
public static void main(String[] args) { List<String> texts = new ArrayList<>(); texts.add("test"); texts.add("test"); Path dest = Paths.get("twinkle.txt"); Charset cs = Charset.forName("US-ASCII"); try {/* w ww . j a va2 s. com*/ Path p = Files.write(dest, texts, cs, StandardOpenOption.WRITE, StandardOpenOption.CREATE); System.out.println("Text was written to " + p.toAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); // Get an iterator for the list Iterator<String> nameIterator = names.iterator(); // Iterate over all elements in the list while (nameIterator.hasNext()) { // Get the next element from the list String name = nameIterator.next(); System.out.println(name); }//from w w w .j a v a 2s.c o m }
From source file:Main.java
public static void main(String[] args) { List<String> myList = new ArrayList<String>(); myList.add("A"); myList.add("B"); myList.add("C"); myList.add("D"); Set<String> mySet = new HashSet<String>(myList); for (Object theFruit : mySet) System.out.println(theFruit); }
From source file:Main.java
public static void main(String[] a) { List<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); ListIterator iter = list.listIterator(1); while (iter.hasNext()) { System.out.println(iter.next()); }//from w w w . j a v a2 s .co m }
From source file:Main.java
public static void main(String[] a) { List<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); ListIterator iter = list.listIterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w w w. ja va 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("notepad.exe"); ProcessBuilder pb = new ProcessBuilder(list); List<String> list2 = new ArrayList<String>(); list2.add("text.txt"); // set the command list pb.command(list2);//from w ww .j a v a 2 s . c o m System.out.println(pb.command()); }
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); arlst.add("CSS"); arlst.add("HTML"); arlst.add("PHP"); // search the list for key int index = Collections.binarySearch(arlst, "HTML"); System.out.println(index);//w w w .j av a 2s . c om }
From source file:Main.java
public static void main(String[] args) { List<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); String[] colors = new String[list.size()]; list.toArray(colors);//from w w w . ja v a2s . c o m for (int i = 0; i < colors.length; i++) { System.out.println("color = " + colors[i]); } }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); Collections.sort(list);/*w ww . jav a2 s. c o m*/ System.out.println("List: " + list); int index = Collections.binarySearch(list, "CSS"); System.out.println("CSS in List is at " + index); index = Collections.binarySearch(list, "Javascript"); System.out.println("Javascript in List is at " + index); }