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) {
    Main testJFrame = new Main();

    List<String> columns = new ArrayList<String>();
    List<String[]> values = new ArrayList<String[]>();

    columns.add("col1");
    columns.add("col2");
    columns.add("col3");

    for (int i = 0; i < 100; i++) {
        values.add(new String[] { "val" + i + " col1", "val" + i + " col2", "val" + i + " col3" });
    }//ww w  .  j  a  v  a 2s.  co  m

    TableModel tableModel = new DefaultTableModel(values.toArray(new Object[][] {}), columns.toArray());
    JTable table = new JTable(tableModel);
    testJFrame.setLayout(new BorderLayout());
    testJFrame.add(new JScrollPane(table), BorderLayout.CENTER);

    testJFrame.add(table.getTableHeader(), BorderLayout.NORTH);

    testJFrame.setVisible(true);
    testJFrame.setSize(200, 200);
}

From source file:Main.java

public static void main(String[] args) {
    Path myText_path = Paths.get("C:/tutorial/wiki", "wiki.txt");
    Charset charset = Charset.forName("UTF-8");
    ArrayList<String> lines = new ArrayList<>();
    lines.add("\n");
    lines.add("tutorial");

    try {/*w w w  .  j  a  v  a2s  .c  o m*/
        Files.write(myText_path, lines, charset, StandardOpenOption.APPEND);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    List mylist = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        Certificate c = cf.generateCertificate(in);
        mylist.add(c);/*w w w  .j  a v a 2  s  .c  o m*/
    }
    CertPath cp = cf.generateCertPath(mylist);
    List cplist = cp.getCertificates();
    Object[] o = cplist.toArray();
    for (int i = 0; i < o.length; i++) {
        X509Certificate c = (X509Certificate) o[i];
        System.out.println(c.getSubjectDN());
        byte[] pbk = c.getPublicKey().getEncoded();
        for (int j = 0; j < pbk.length; j++) {
            System.out.print(pbk[j] + ",");
        }
        System.out.println("\nIssued by " + c.getIssuerDN());
    }
}

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, String> grades = new HashMap<Integer, String>();

    grades.put(1, "A");
    grades.put(2, "B");
    grades.put(3, "C");
    grades.put(4, "D");
    grades.put(5, "E");

    String value = grades.get(1);

    List<String> dayNames = new ArrayList<String>();
    dayNames.add("Sunday");
    dayNames.add("Monday");
    dayNames.add("Tuesday");
    dayNames.add("Wednesday");

    String firstDay = dayNames.get(0);
}

From source file:Main.java

public final static void main(String[] args) throws Exception {
    final ArrayList<String> list = new ArrayList<String>();

    ParserDelegator parserDelegator = new ParserDelegator();
    ParserCallback parserCallback = new ParserCallback() {
        public void handleText(final char[] data, final int pos) {
        }//from  w  ww .j a  v  a 2  s. c  om

        public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) {
            if (tag == Tag.A) {
                String address = (String) attribute.getAttribute(Attribute.HREF);
                list.add(address);
            }
        }

        public void handleEndTag(Tag t, final int pos) {
        }

        public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) {
        }

        public void handleComment(final char[] data, final int pos) {
        }

        public void handleError(final java.lang.String errMsg, final int pos) {
        }
    };
    parserDelegator.parse(new FileReader("a.html"), parserCallback, false);
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
    List<Particle> allTheParticles = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        allTheParticles.add(new Particle(i, allTheParticles));
    }//from   w ww  .  ja  v a 2  s.  co  m
    while (true) {
        executor.invokeAll(allTheParticles);
        executor.invokeAll(allTheParticles);
    }
}

From source file:in.java

public static void main (String[] args) {
    List<MyEnum> enums = new ArrayList<MyEnum>();
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> m1 = new LinkedHashMap<String, String>();
    m1.put("1", "One");
    m1.put("3", "Three");

    Map<String, String> m2 = new LinkedHashMap<String, String>();
    m2.put("2", "Two");
    m2.put("4", "Four");

    List<String> list = new ArrayList<String>();
    list.addAll(m1.keySet());//from ww  w  . j a va2 s .co m
    list.addAll(m2.keySet());
    for (String s : list) {
        System.out.println(s);
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {/*  ww  w. j ava2s .co m*/
        BufferedReader input = new BufferedReader(new FileReader(args[0]));
        ArrayList list = new ArrayList();
        String line;
        while ((line = input.readLine()) != null) {
            list.add(line);
        }
        input.close();

        Collections.reverse(list);

        PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
        for (Iterator i = list.iterator(); i.hasNext();) {
            output.println((String) i.next());
        }
        output.close();
    } catch (IOException e) {
        System.err.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final List<String> list = new ArrayList<String>();
    ParserDelegator parserDelegator = new ParserDelegator();
    ParserCallback parserCallback = new ParserCallback() {
        public void handleText(final char[] data, final int pos) {
            list.add(new String(data));
        }/* w w  w .  j  ava2s . c  o  m*/

        public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) {
        }

        public void handleEndTag(Tag t, final int pos) {
        }

        public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) {
        }

        public void handleComment(final char[] data, final int pos) {
        }

        public void handleError(final java.lang.String errMsg, final int pos) {
        }
    };
    parserDelegator.parse(new FileReader("a.html"), parserCallback, true);
    System.out.println(list);
}