List of usage examples for java.util Collection add
boolean add(E e);
From source file:MainClass.java
public static void main(String[] a) { Collection c = new ArrayList(); c.add("1"); c.add("2");/*from w w w . ja v a2 s . c o m*/ c.add("3"); Iterator i = c.iterator(); while (i.hasNext()) { System.out.println(i.next()); } }
From source file:Main.java
public static void main(String[] a) { Collection<String> c = new ArrayList<String>(); c.add("1"); c.add("2");//from w w w .j av a 2 s . com c.add("3"); Iterator i = c.iterator(); while (i.hasNext()) { System.out.println(i.next()); } }
From source file:Main.java
public static void main(String[] args) { Collection<Integer> col = new ArrayList<Integer>(); col.add(0); ArrayDeque<Integer> deque = new ArrayDeque<Integer>(col); deque.add(3);/*from w w w.j a v a 2 s . co m*/ deque.add(18); deque.add(25); deque.add(18); System.out.println(deque); }
From source file:Main.java
public static void main(String[] args) { Collection<Integer> list = new ArrayList<Integer>(); list.add(9); Vector vec = new Vector(list); vec.add(4);/*from ww w . j a v a 2s . c om*/ vec.add(3); vec.add(2); vec.add(1); System.out.println(vec); }
From source file:Main.java
public static void main(String args[]) { Collection<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(1); arrlist.add(2);//from ww w . j a va2 s . c o m arrlist.add(3); arrlist.add(4); arrlist.add(5); ArrayList<Integer> anotherList = new ArrayList<Integer>(arrlist); System.out.println(anotherList); }
From source file:Main.java
public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // add some elements list.add("Hello"); list.add("from java2s.com"); list.add("10"); // print the list System.out.println("LinkedList:" + list); // create a new collection and add some elements Collection collection = new ArrayList(); collection.add("One"); collection.add("Two"); collection.add("Three"); // append the collection in the LinkedList list.addAll(collection);//w w w .j a va 2 s.c om // print the new list System.out.println("LinkedList:" + list); }
From source file:Main.java
public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // add some elements list.add("Hello"); list.add("from java2s.com"); list.add("10"); // print the list System.out.println("LinkedList:" + list); // create a new collection and add some elements Collection collection = new ArrayList(); collection.add("One"); collection.add("Two"); collection.add("Three"); // add the collection in the LinkedList at index 2 list.addAll(2, collection);// w w w. j a va 2s . c om // print the new list System.out.println("LinkedList:" + list); }
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:PlanetSet.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; Collection planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]); }/*from w w w . j ava2 s . c o m*/ String s[] = (String[]) planets.toArray(new String[0]); for (int i = 0, n = s.length; i < n; i++) { System.out.println(s[i]); } planets.remove(names[3]); System.out.println(names[1] + " " + planets.contains(names[1])); System.out.println(names[3] + " " + planets.contains(names[3])); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse("server.xml"); Element root = document.getDocumentElement(); Element rootElement = document.getDocumentElement(); Collection<Server> svr = new ArrayList<Server>(); svr.add(new Server()); for (Server i : svr) { Element server = document.createElement("server"); rootElement.appendChild(server); Element name = document.createElement("name"); name.appendChild(document.createTextNode(i.getName())); server.appendChild(name);//w w w . ja v a 2s. c o m Element port = document.createElement("port"); port.appendChild(document.createTextNode(Integer.toString(i.getPort()))); server.appendChild(port); root.appendChild(server); } DOMSource source = new DOMSource(document); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); StreamResult result = new StreamResult("server.xml"); transformer.transform(source, result); }