Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

In this page you can find the example usage for java.util ArrayList ArrayList.

Prototype

public ArrayList() 

Source Link

Document

Constructs an empty list with an initial capacity of ten.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String DEFAULT_DRIVER = "org.sqlite.JDBC";
    String DEFAULT_URL = "jdbc:sqlite:data/test.db";

    Connection conn = createConnection(DEFAULT_DRIVER, DEFAULT_URL);
    createTable(conn);//from w  w w  .  j  ava 2  s.c  om

    List<Person> people = new ArrayList<Person>();
    people.add(new Person("A", "a"));
    people.add(new Person("B", "b"));
    people.add(new Person("C", "c"));
    saveAll(conn, people);

    List<Person> rows = findAll(conn);
    System.out.println(rows);
    close(conn);
}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(Vehicals.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Vehicals vehicals = new Vehicals();

    List<Car> cars = new ArrayList<Car>();
    Car c = new Car();
    c.setName("Mercedes");
    cars.add(c);// w  w  w .ja v a 2 s . com

    c = new Car();
    c.setName("BMW");
    cars.add(c);
    vehicals.setCar(cars);
    m.marshal(vehicals, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    List<Element> elementList = new ArrayList<Element>();
    List<Item> itemList = new ArrayList<Item>();
    Element element1 = new Element();
    Element element2 = new Element();
    Item item1 = new Item();
    Item item2 = new Item();
    Elements elements = new Elements();

    item1.setId(1);/*from  w  w w. j  ava  2  s. c  o  m*/
    item1.setName("Test1");
    item2.setId(2);
    item2.setName("Test2");
    itemList.add(item1);
    itemList.add(item2);

    element1.setProperty1("prop1");
    element1.setProperty2("prop2");
    element1.setType(2);
    element1.setItems(itemList);

    element2.setProperty1("prop11");
    element2.setProperty2("prop22");
    element2.setType(22);
    element2.setItems(itemList);

    elementList.add(element1);
    elementList.add(element2);

    elements.setElements(elementList);

    System.out.println("------- Object to XML -----------\n");
    JAXBContext jaxbContext = JAXBContext.newInstance(Elements.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    // output pretty printed
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    jaxbMarshaller.marshal(elements, System.out);

    System.out.println("\n------- XML to Object -----------\n");

    String xml = "<elements><element><items><item><id>1</id><name>Test1</name></item><item><id>2</id><name>Test2</name></item></items><property1>prop1</property1><property2>prop2</property2><type>2</type></element><element><items><item><id>1</id><name>Test1</name></item><item><id>2</id><name>Test2</name></item></items><property1>prop11</property1><property2>prop22</property2><type>22</type></element></elements>";
    StringReader reader = new StringReader(xml);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Elements elementsOut = (Elements) jaxbUnmarshaller.unmarshal(reader);
    System.out.println(elementsOut);

}

From source file:eu.europeana.datamigration.ese2edm.LogCleaner.java

public static void main(String[] args) {
    try {//from ww w . j  a v  a2  s  .co  m
        List<String> lines = FileUtils.readLines(new File("/home/gmamakis/test.log"));
        List<String> newLines = new ArrayList<String>();
        for (String line : lines) {
            if (!line.startsWith("Apr")) {
                newLines.add(line);
            }
        }
        FileUtils.writeLines(new File("/home/gmamakis/rdfslabel.log"), newLines);
    } catch (IOException ex) {
        Logger.getLogger(LogCleaner.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:JavaCompilerDemo.java

public static void main(String[] args) {
    String sourceFile = "c:/HelloWorld.Java";
    JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null);

    // prepare the source file(s) to compile
    List<File> sourceFileList = new ArrayList<File>();
    sourceFileList.add(new File(sourceFile));
    Iterable<? extends JavaFileObject> compilationUnits = fileManager
            .getJavaFileObjectsFromFiles(sourceFileList);
    CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits);
    task.run();/*from   w w w.  ja  v a  2  s. c om*/
    boolean result = task.getResult();
    if (result) {
        System.out.println("Compilation was successful");
    } else {
        System.out.println("Compilation failed");
    }
    try {
        fileManager.close();
    } catch (IOException e) {
    }
}

From source file:minikbextractor.MiniKBextractor.java

/**
 * @param args the command line arguments
 *//*w ww  .  j a va2  s .c  o  m*/
public static void main(String[] args) {
    String adomFile = "in/agronomicTaxon.owl";

    ArrayList<Source> sources = new ArrayList();

    SparqlProxy spInAgrovoc = SparqlProxy
            .getSparqlProxy("http://amarger.murloc.fr:8080/Agrovoc2KB_TESTClass_out/");
    HashMap<String, String> limitSpOutAgrovoc = new HashMap<>();
    //limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_5608", "http://amarger.murloc.fr:8080/Agrovoc_mini_Paspalum/");
    limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_148",
            "http://amarger.murloc.fr:8080/Agrovoc_mini_Aegilops/");
    //imitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_5435", "http://amarger.murloc.fr:8080/Agrovoc_mini_Oryza/");
    limitSpOutAgrovoc.put("http://aims.fao.org/aos/agrovoc/c_7950",
            "http://amarger.murloc.fr:8080/Agrovoc_mini_Triticum/");

    String nameAgrovoc = "Agrovoc";

    sources.add(new Source(spInAgrovoc, nameAgrovoc, limitSpOutAgrovoc, adomFile));

    SparqlProxy spInTaxRef = SparqlProxy.getSparqlProxy("http://amarger.murloc.fr:8080/TaxRef2RKB_out_TEST/");
    HashMap<String, String> limitSpOutTaxRef = new HashMap<>();
    //limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/195870", "http://amarger.murloc.fr:8080/TaxRef_mini_Paspalum/");
    limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/188834",
            "http://amarger.murloc.fr:8080/TaxRef_mini_Aegilops/");
    //limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/195564", "http://amarger.murloc.fr:8080/TaxRef_mini_Oryza/");
    limitSpOutTaxRef.put("http://inpn.mnhn.fr/espece/cd_nom/198676",
            "http://amarger.murloc.fr:8080/TaxRef_mini_Triticum/");
    //String limitUriTaxRef = "http://inpn.mnhn.fr/espece/cd_nom/187444"; //Poaceae
    String nameTaxRef = "TaxRef   ";

    sources.add(new Source(spInTaxRef, nameTaxRef, limitSpOutTaxRef, adomFile));

    SparqlProxy spInNCBI = SparqlProxy.getSparqlProxy("http://amarger.murloc.fr:8080/Ncbi2RKB_out/");
    HashMap<String, String> limitSpOutNCBI = new HashMap<>();
    //limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=147271", "http://amarger.murloc.fr:8080/NCBI_mini_Paspalum/");
    limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4480",
            "http://amarger.murloc.fr:8080/NCBI_mini_Aegilops/");
    //limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4527", "http://amarger.murloc.fr:8080/NCBI_mini_Oryza/");
    limitSpOutNCBI.put("http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=4564",
            "http://amarger.murloc.fr:8080/NCBI_mini_Triticum/");
    String nameNCBI = "NCBI";

    sources.add(new Source(spInNCBI, nameNCBI, limitSpOutNCBI, adomFile));

    for (Source s : sources) {
        //System.out.println(s.getStatUnderLimit());
        s.exportAllSubRKB();
        System.out.println("------------------------------------");
    }
    System.exit(0);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map<String, List<String>> fontFaceNames = new HashMap<String, List<String>>();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();

    for (int i = 0; i < fonts.length; i++) {
        String familyName = fonts[i].getFamily();
        String faceName = fonts[i].getName();

        List<String> list = fontFaceNames.get(familyName);
        if (list == null) {
            list = new ArrayList<String>();
            fontFaceNames.put(familyName, list);
        }//from w w w.  j ava2  s. c  o m
        list.add(faceName);
    }
    System.out.println(fontFaceNames);

}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(PayTypeList.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    PayTypeList paymentType = new PayTypeList();

    List<String> paymentTypes = new ArrayList<String>();
    paymentTypes.add("one");
    paymentTypes.add("two");
    paymentTypes.add("three");
    paymentType.setPayType(paymentTypes);

    m.marshal(paymentType, System.out);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    List mylist = new ArrayList();

    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    mylist.add(c);/*from  ww w  .  ja  va  2 s  . c  o  m*/

    CertPath cp = cf.generateCertPath(mylist);

    FileInputStream kin = new FileInputStream(args[0]);
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(kin, args[1].toCharArray());

    PKIXParameters params = new PKIXParameters(ks);
    params.setRevocationEnabled(false);

    CertPathValidator cpv = CertPathValidator.getInstance("PKIX");

    PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);

    PublicKey pbk = result.getPublicKey();
    byte[] pkenc = pbk.getEncoded();
    BigInteger pk = new BigInteger(pkenc);
    System.out.println(pk.toString(16));

    TrustAnchor anc = result.getTrustAnchor();
    X509Certificate xc = anc.getTrustedCert();
    System.out.println(xc.getSubjectDN());
    System.out.println(xc.getIssuerDN());

}

From source file:formats.db.fileformats.csv.RunnerCsv.java

public static void main(String[] args) throws IOException {

    CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(',');

    //initialize the CSVParser object

    CSVParser parser = new CSVParser(new FileReader("D:\\customers.csv"), format);

    List<Customers> customersList = new ArrayList<Customers>();
    for (CSVRecord record : parser) {
        Customers customers = new Customers();

        customers.setId_cs(Integer.parseInt(record.get("id_cs")));
        customers.setF_name(record.get("f_name"));
        customers.setL_name(record.get("l_name"));
        customers.setDiscount(Integer.parseInt(record.get("discount")));
        customers.setLicense(record.get("license"));

        customersList.add(customers);/* w w w. j a  va2  s .  co m*/
    }
    //close the parser
    parser.close();

    System.out.println(customersList);
}