List of usage examples for java.util List add
boolean add(E e);
From source file:Main.java
public static void main(String[] a) { List<String> list = new ArrayList<String>(); list.add("A"); List list2 = ((List) ((ArrayList) list).clone()); System.out.println(list);/*from w w w . j a v a 2 s.c o m*/ System.out.println(list2); list.clear(); System.out.println(list); System.out.println(list2); }
From source file:Main.java
public static void main(String args[]) throws Exception { List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); List<String> list2 = new ArrayList<String>(); list2.add("X"); list2.add("Y"); list2.add("Z"); list.addAll(list2);/*w ww . j a va2 s .c o m*/ list.addAll(1, list2); System.out.println(list); }
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"); 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); nameIterator.remove();/*from w ww . jav a2s .com*/ } System.out.println(names); }
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); arlst.add("A"); arlst.add("B"); arlst.add("C"); arlst.add("from java2s.com"); // create typesafe view of the list List<String> tslst = Collections.checkedList(arlst, String.class); System.out.println(tslst);//from w w w .ja v a 2s.c o m }
From source file:Main.java
public static void main(String args[]) { List<Character> list = new ArrayList<Character>(); list.add('X'); System.out.println("Element added to list: " + list.get(0)); Collection<Character> immutableCol = Collections.unmodifiableCollection(list); immutableCol.add('Y'); }
From source file:Main.java
public static void main(final String[] args) { List<String> stringCollection = new ArrayList<>(); stringCollection.add("ddd2"); stringCollection.add("aaa2"); stringCollection.add("bbb1"); stringCollection.add("aaa1"); stringCollection.add("bbb3"); stringCollection.add("ccc"); stringCollection.add("bbb2"); stringCollection.add("ddd1"); stringCollection.stream().sorted().filter((s) -> s.startsWith("a")).forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("acowa"); list.add("cow"); list.add("aow"); Collections.sort(list, new Comparator<String>() { @Override//from ww w . ja v a2s .co m public int compare(String o1, String o2) { if (o1.length() > o2.length()) { return 1; } else { return o1.compareTo(o2); } } }); System.out.println(list); }
From source file:MainClass.java
public static void main(String[] a) { List list = new ArrayList(10); Object anObject = "A"; list.add("N"); Collections.fill(list, anObject); System.out.println(list);/* www .ja va 2 s . co m*/ System.out.println(list.size()); }
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<String> iter = list.listIterator(list.size()); while (iter.hasPrevious()) { System.out.println(iter.previous()); iter.add("a"); break;/*ww w .jav a 2 s.c o m*/ } System.out.println(list); }
From source file:Main.java
public static void main(String[] argv) { List<URL> urlList = new ArrayList<URL>(); try {//from www .j a va2 s. c o m urlList.add(new URL("http://www.java2s.com")); } catch (MalformedURLException e) { } String s = urlList.get(0).getHost(); }