Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

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

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:Main.java

public static void main(String args[]) {
    List<Integer> list = Arrays.asList(1, 2, 3);
    ArrayList<Integer> val = new ArrayList<Integer>(list);
    System.out.println(val.size());
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> ids = new ArrayList<>();

    int total = ids.size(); // total will be zero

    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);

    ids.add(new Integer(10)); // Adding an Integer object.
    ids.add(20); // Autoboxing
    ids.add(30); // Autoboxing

    total = ids.size(); // total will be 3

    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);

    ids.clear();/* ww w  . jav  a 2  s  . com*/

    total = ids.size(); // total will be 0
    System.out.println("ArrayList size is  " + total);
    System.out.println("ArrayList elements are   " + ids);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    StyleSheet st = new StyleSheet();
    st.loadTagStyle("body", "leading", "16,0");
    PdfWriter.getInstance(document, new FileOutputStream("html2.pdf"));
    document.open();//ww w . jav  a 2 s  .c  o m
    ArrayList p = HTMLWorker.parseToList(new FileReader("example.html"), st);
    for (int k = 0; k < p.size(); ++k)
        document.add((Element) p.get(k));
    document.close();
}

From source file:MainClass.java

public static void main(String[] a) {

    ArrayList list = new ArrayList();
    list.add("A");
    list.ensureCapacity(10);//from w ww.  j av  a2 s.  c o  m

    System.out.println(list.size());
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    System.out.println("Initial size of al: " + al.size());

    al.add("C");//from w  ww . j a v  a  2  s .c om
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");
    al.add(1, "java2s.com");

    System.out.println("Size of al after additions: " + al.size());

    System.out.println("Contents of al: " + al);

    al.remove("F");
    al.remove(2);

    System.out.println("Size of al after deletions: " + al.size());
    System.out.println("Contents of al: " + al);
}

From source file:MainClass.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    System.out.println("Initial size of al: " + al.size());

    al.add("C");/*from w ww  .j  av a2s.c om*/
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");
    al.add(1, "A2");

    System.out.println("Size of al after additions: " + al.size());

    System.out.println("Contents of al: " + al);

    al.remove("F");
    al.remove(2);

    System.out.println("Size of al after deletions: " + al.size());
    System.out.println("Contents of al: " + al);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    StyleSheet styles = new StyleSheet();
    styles.loadTagStyle("ol", "leading", "16,0");
    PdfWriter.getInstance(document, new FileOutputStream("html3.pdf"));
    document.open();//from   w  w  w .  j  a va  2  s .  c  o m
    ArrayList objects;
    objects = HTMLWorker.parseToList(new FileReader("data.html"), styles);
    for (int k = 0; k < objects.size(); ++k)
        document.add((Element) objects.get(k));
    document.close();
}

From source file:Main.java

public static void main(String[] args) {
    String givenstring = "this is a test this is a another test";
    String[] words = givenstring.split(" ");

    ArrayList<String> arr = new ArrayList<String>();
    for (int i = 0; i < words.length; i++) {
        arr.add(words[i]);//from  ww w. j a va2 s. c  o  m
    }
    while (arr.size() != 0) {
        String word = arr.get(0);
        int frequency = Collections.frequency(arr, word);
        arr.removeAll(Collections.singleton(word));
        System.out.println(word + frequency);
    }
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    int totalElements = arrayList.size();
    for (int index = 0; index < totalElements; index++)
        System.out.println(arrayList.get(index));
}

From source file:com.github.xbn.examples.io.non_xbn.SizeOrderAllFilesInDirXmpl.java

public static final void main(String[] ignored) {
    File fDir = (new File("R:\\jeffy\\programming\\sandbox\\xbnjava\\xbn\\"));
    Collection<File> cllf = FileUtils.listFiles(fDir, (new String[] { "java" }), true);

    //Add all file paths to a Map, keyed by size.
    //It's actually a map of lists-of-files, to
    //allow multiple files that happen to have the
    //same length.

    TreeMap<Long, List<File>> tmFilesBySize = new TreeMap<Long, List<File>>();
    Iterator<File> itrf = cllf.iterator();
    while (itrf.hasNext()) {
        File f = itrf.next();/*w ww . j  a  va  2  s . co  m*/
        Long LLen = f.length();
        if (!tmFilesBySize.containsKey(LLen)) {
            ArrayList<File> alf = new ArrayList<File>();
            alf.add(f);
            tmFilesBySize.put(LLen, alf);
        } else {
            tmFilesBySize.get(LLen).add(f);
        }
    }

    //Iterate backwards by key through the map. For each
    //List<File>, iterate through the files, printing out
    //its size and path.

    ArrayList<Long> alSize = new ArrayList<Long>(tmFilesBySize.keySet());
    for (int i = alSize.size() - 1; i >= 0; i--) {
        itrf = tmFilesBySize.get(alSize.get(i)).iterator();
        while (itrf.hasNext()) {
            File f = itrf.next();
            System.out.println(f.length() + ": " + f.getPath());
        }
    }
}