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) {
    List<Apple> inventory = new ArrayList<>();
    inventory.addAll(Arrays.asList(new Apple(80, "green"), new Apple(155, "green"), new Apple(120, "red")));

    inventory.sort((a1, a2) -> a1.getWeight().compareTo(a2.getWeight()));
    System.out.println(inventory);
}

From source file:Main.java

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

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("java2s.com");

    Comparator comparator = Collections.reverseOrder();
    System.out.println(arrayList);

    Collections.sort(arrayList, comparator);
    System.out.println(arrayList);
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> people = new ArrayList<Person>();
    people.add(new Person("C", 21));
    people.add(new Person("T", 20));
    people.add(new Person("B", 35));
    people.add(new Person("A", 22));
    people.sort(Comparator.comparing(Person::getName));
    people.forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {
    // Create a list of strings
    List<String> names = new ArrayList<>();

    // Get an iterator for the list
    Iterator<String> nameIterator = names.iterator();
}

From source file:Main.java

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

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("E");

    Comparator comparator = Collections.reverseOrder();
    System.out.println(arrayList);

    Collections.sort(arrayList, comparator);
    System.out.println(arrayList);
}

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);//from   w  ww . j av  a 2s. com
    }

    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(final String[] args) {
    List<String> stringCollection = new ArrayList<>();
    stringCollection.add("ddd2");
    stringCollection.add("aaa2");
    stringCollection.add("bbb1");
    stringCollection.add("aaa1");
    stringCollection.add("bbb3");
    stringCollection.add("ccc");
    stringCollection.add("bbb2");
    stringCollection.add("ddd1");

    Optional<String> reduced = stringCollection.stream().sorted().reduce((s1, s2) -> s1 + "#" + s2);
    reduced.ifPresent(System.out::println);

}

From source file:Main.java

public static void main(String[] argv) {
    List list = new ArrayList();

    // Create a left-aligned tab stop at 100 pixels from the left margin
    float pos = 100;
    int align = TabStop.ALIGN_LEFT;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);/*w  w w.  ja  v  a 2  s.c o  m*/
}

From source file:Main.java

public static void main(String[] argv) {

    List<URL> urlList = new ArrayList<URL>();
    try {//from w w w  .java 2 s  . c  o m
        urlList.add(new URL("http://www.java2s.com"));
    } catch (MalformedURLException e) {
    }
    String s = urlList.get(0).getHost();
}

From source file:Main.java

public static void main(String args[]) {
    // create arraylist       
    ArrayList<String> arlst = new ArrayList<String>();

    arlst.add("A");
    arlst.add("B");
    arlst.add("C");
    arlst.add("D");

    // search for key 
    int index = Collections.binarySearch(arlst, "D", Collections.reverseOrder());

    System.out.println(index);/*from  w  ww  .ja  va  2 s  . c om*/

    index = Collections.binarySearch(arlst, "D");

    System.out.println(index);
}