List of usage examples for java.util List add
boolean add(E e);
From source file:ToArray.java
public static void main(String[] args) { List list = new ArrayList(); list.add("Blobbo"); list.add("Cracked"); list.add("Dumbo"); // list.add(new Date()); // Don't mix and match! // Convert a collection to Object[], which can store objects // of any type. Object[] ol = list.toArray(); System.out.println("Array of Object has length " + ol.length); // This would throw an ArrayStoreException if the line // "list.add(new Date())" above were uncommented. String[] sl = (String[]) list.toArray(new String[0]); System.out.println("Array of String has length " + sl.length); }
From source file:MainClass.java
public static void main(String[] args) { List cats = new ArrayList(); for (int i = 0; i < 7; i++) cats.add(new Cat(i)); Iterator e = cats.iterator(); while (e.hasNext()) ((Cat) e.next()).id();//from w w w.ja va 2s . c o m }
From source file:Main.java
public static void main(String[] args) { String s = "(123, 234; 345, 456) (567, 788; 899, 900)"; Matcher m = Pattern.compile("\\d+").matcher(s); List<Integer> numbers = new ArrayList<Integer>(); while (m.find()) { numbers.add(Integer.parseInt(m.group())); }/*from w w w . ja v a2 s . c o m*/ System.out.println(numbers); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); for (int i = 0; i < 10; i++) list.add(""); Collections.fill(list, "Hello"); System.out.println(list);/*from ww w .ja v a 2 s . c o m*/ }
From source file:AIR.Common.Sql.DbHelper.java
public static void main(String[] argv) { List<Long> x = new java.util.ArrayList<Long>(); x.add(new Long(10)); x.add(new Long(11)); String z = getDbCsvFromMathTypes(x); System.err.println(z);/*from w ww. ja v a 2 s .c o m*/ }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainRmiClient.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.client"); QuoteServiceClient client = context.getBean("client", QuoteServiceClient.class); List<Quote> myQuotes = new ArrayList<Quote>(); myQuotes.add(client.getMyQuote("APRESS")); myQuotes.add(client.getMyQuote("SPRNG")); myQuotes.add(client.getMyQuote("INTGRN")); for (Quote myQuote : myQuotes) { System.out.println("Symbol : " + myQuote.getSymbol()); System.out.println("Price :" + myQuote.getPrice()); System.out.println("Exchange: " + myQuote.getExchangeId()); }/* w w w .ja v a2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Content.class); List<String> strings = new ArrayList<String>(2); strings.add("foo"); strings.add("bar"); Content content = new Content(); content.setKeywords(strings);/*from w w w . j av a 2 s .c o m*/ Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(content, System.out); }
From source file:Main.java
public static void main(String[] args) { List numbers = new ArrayList(); for (int i = 0; i < 25; i++) { numbers.add(i); }//ww w. j a v a2 s . c o m System.out.println(Arrays.toString(numbers.toArray())); Collections.rotate(numbers, 10); System.out.println(Arrays.toString(numbers.toArray())); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out); Namespace ns1 = eventFactory.createNamespace("ns1", "http://www.e.com/ns1"); Namespace ns2 = eventFactory.createNamespace("ns2", "http://www.e.com/ns2"); List<Namespace> namespaceList = new ArrayList<Namespace>(); namespaceList.add(ns1); namespaceList.add(ns2);//from w w w . j a va2 s.com Attribute attribute = eventFactory.createAttribute(ns2.getPrefix(), ns2.getNamespaceURI(), "attribute", "true"); writer.add(eventFactory.createStartElement(ns1.getPrefix(), ns1.getNamespaceURI(), "sample", Collections.singletonList(attribute).iterator(), namespaceList.iterator())); writer.add(eventFactory.createEndDocument()); writer.flush(); }
From source file:Main.java
public static void main(String args[]) { // create link list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-8); list.add(4);//from ww w .j av a 2 s .com list.add(-5); list.add(1); System.out.println("Min value is: " + Collections.min(list)); }