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: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);/*from   www  .  j av  a2 s  . com*/
    }
    CertPath cp = cf.generateCertPath(mylist);
    System.out.println(cp);
}

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
    Enumeration<String> keys = bundle.getKeys();
    ArrayList<String> temp = new ArrayList<String>();

    for (Enumeration<String> e = keys; keys.hasMoreElements();) {
        String key = e.nextElement();
        if (key.startsWith("java2s")) {
            temp.add(key);//from ww  w  .  j ava  2 s .  com
        }
    }

    String[] result = new String[temp.size()];

    for (int i = 0; i < temp.size(); i++) {
        result[i] = bundle.getString(temp.get(i));
    }
    System.out.println(Arrays.toString(result));
}

From source file:Main.java

public static void main(String[] args) {
    String string = "var1[value1], var2[value2], var3[value3]";
    Pattern pattern = Pattern.compile("(\\[)(.*?)(\\])");
    Matcher matcher = pattern.matcher(string);

    List<String> listMatches = new ArrayList<String>();

    while (matcher.find()) {
        listMatches.add(matcher.group(2));
    }//from w ww  .ja  va 2  s .  c  o m

    for (String s : listMatches) {
        System.out.println(s);
    }
}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    executors = new ForkJoinPool();
    List<Long> sequence = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        sequence.add(fib(i));//from   ww w  . java 2  s .co  m
    }
    System.out.println(sequence);
}

From source file:Main.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++)
        src.add(coins[i]);//www.  j a  v  a  2 s  .c o m

    List dst = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        dst.add("");

    Collections.copy(dst, src);

    ListIterator liter = dst.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:ProcessBuilderDemo.java

public static void main(String argv[]) throws InterruptedException, IOException {

    List<String> command = new ArrayList<String>();
    command.add("notepad");
    command.add("foo.txt");
    ProcessBuilder builder = new ProcessBuilder(command);
    Map<String, String> environ = builder.environment();
    environ.put("PATH", "/windows;/windows/system32;/winnt");
    builder.directory(new File(System.getProperty("user.home")));

    final Process godot = builder.start();

    godot.waitFor();//from   w w w  .j  a va2 s  . c o  m

    System.out.println("Program terminated!");
    return;
}

From source file:Test.java

public static void main(String[] args) {
    final AtomicLong orderIdGenerator = new AtomicLong(0);
    final List<Item> orders = Collections.synchronizedList(new ArrayList<Item>());

    for (int i = 0; i < 10; i++) {
        Thread orderCreationThread = new Thread(new Runnable() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    long orderId = orderIdGenerator.incrementAndGet();
                    Item order = new Item(Thread.currentThread().getName(), orderId);
                    orders.add(order);/*from ww  w  . j a v a  2 s .  co  m*/
                }
            }
        });
        orderCreationThread.setName("Order Creation Thread " + i);
        orderCreationThread.start();
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Set<Long> orderIds = new HashSet<Long>();
    for (Item order : orders) {
        orderIds.add(order.getID());
        System.out.println("Order id:" + order.getID());
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++)
        src.add(coins[i]);//w  w w. ja va  2  s.c om

    List dst = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        dst.add("");

    Collections.copy(dst, src);

    ListIterator liter = dst.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

    Collections.fill(src, "no coins");

    liter = src.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:Main.java

public static void main(String s[]) {
    DefaultTableModel model = new DefaultTableModel();

    model.addColumn("Col1");
    model.addColumn("Col2");

    model.addRow(new Object[] { "1", "v2" });
    model.addRow(new Object[] { "2", "v2" });

    List<String> numdata = new ArrayList<String>();
    for (int count = 0; count < model.getRowCount(); count++) {
        numdata.add(model.getValueAt(count, 0).toString());
    }/*  w  ww  . j a  v  a  2 s  . com*/

    System.out.println(numdata);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url16 = new URL("http://www.java2s.com/style/download.png");
    URL url32 = new URL("http://www.java2s.com/style/download.png");

    final List<Image> icons = new ArrayList<Image>();
    icons.add(ImageIO.read(url16));
    icons.add(ImageIO.read(url32));

    JFrame f = new JFrame();
    f.setIconImages(icons);//from   w  w  w.  j  a v  a  2  s. com
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(200, 100);
    f.setVisible(true);
}