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 array list object List<String> arrlist = new ArrayList<String>(); // populate the list arrlist.add("A"); arrlist.add("B"); arrlist.add("from java2s.com"); System.out.println("List elements before fill: " + arrlist); // fill the list Collections.fill(arrlist, "java2s.com"); System.out.println("List elements after fill: " + arrlist); }
From source file:Main.java
public static void main(String args[]) { // create array list object List<String> arrlist = new ArrayList<String>(); // populate the list arrlist.add("A"); arrlist.add("B"); arrlist.add("from java2s.com"); // create Enumeration Enumeration<String> e = Collections.enumeration(arrlist); while (e.hasMoreElements()) { System.out.println("Value is: " + e.nextElement()); }/* w w w . j ava 2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Foo> foos = new ArrayList<>(); IntStream.range(1, 4).forEach(num -> foos.add(new Foo("Foo" + num))); foos.forEach(f -> IntStream.range(1, 4).forEach(num -> f.bars.add(new Bar("Bar" + num + " <- " + f.name)))); foos.stream().flatMap(f -> f.bars.stream()).forEach(b -> System.out.println(b.name)); }
From source file:Customer.java
public static void main(String[] args) { List<Customer> customers = new ArrayList<>(); customers.add(new Customer("A", "a@gmail.com")); customers.add(new Customer("B", "b@gmail.com")); System.out.println("customers before email change - start"); System.out.println(Customer.toString(customers)); System.out.println("end"); customers.get(1).setEmail("new.email@gmail.com"); System.out.println("customers after email change - start"); System.out.println(Customer.toString(customers)); System.out.println("end"); }
From source file:Main.java
public static void main(String[] args) { // create array list List<Character> list = new ArrayList<Character>(); // populate the list list.add('X'); list.add('Y'); System.out.println("Initial list: " + list); Collection<Character> immutablelist = Collections.unmodifiableCollection(list); // try to modify the list immutablelist.add('Z'); }
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"); // create a synchronized view Collection<String> c = Collections.synchronizedCollection(vector); System.out.println("Sunchronized view is :" + c); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); for (int i = 0; i < 30; i++) { list.add("Hello, World " + i); }//from w w w .j a va2 s. c o m JScrollPane pane = new JScrollPane(new JList(list.toArray())) { @Override public Dimension getPreferredSize() { return new Dimension(200, 250); } }; JOptionPane.showMessageDialog(null, pane); }
From source file:Main.java
public static void main(String args[]) { // create array list object List<String> arrlist = new ArrayList<String>(); // populate the list arrlist.add("A"); arrlist.add("B"); arrlist.add("B"); arrlist.add("B"); arrlist.add("B"); arrlist.add("from java2s.com"); // check frequensy of 'B' int freq = Collections.frequency(arrlist, "B"); System.out.println("Frequency of 'B' is: " + freq); }
From source file:Main.java
public static void main(String[] args) { // create array list object List<String> arrlst = new ArrayList<String>(); // populate the list arrlst.add("A"); arrlst.add("B"); arrlst.add("C"); arrlst.add("D"); arrlst.add("from java2s.com"); System.out.println("The initial list is :" + arrlst); // reverse the list Collections.reverse(arrlst);/*from w w w.j a v a 2 s . c o m*/ System.out.println("The Reverse List is :" + arrlst); }
From source file:Main.java
public static void main(String[] args) { // create array list List<Character> list = new ArrayList<Character>(); // populate the list list.add('X'); list.add('Y'); System.out.println("Initial list: " + list); // make the list unmodifiable List<Character> immutablelist = Collections.unmodifiableList(list); // try to modify the list immutablelist.add('Z'); }