Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Main.java

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

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    ListIterator<String> listIterator = aList.listIterator();
    listIterator.next();//from w  w w. j a v a2  s.  c  o  m

    listIterator.set("100");
    for (String str : aList) {
        System.out.println(str);
    }
}

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");

    System.out.println(arrayList);
    Collections.swap(arrayList, 0, 4);
    System.out.println(arrayList);
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<Integer> arrayList = new ArrayList<Integer>();

    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("1"));
    arrayList.add(new Integer("8"));
    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("5"));

    Object obj = Collections.max(arrayList);
    System.out.println(obj);/*  w w  w  .j a  v a2s. com*/
}

From source file:twilio.SmsSender.java

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

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    Account account = client.getAccount();

    MessageFactory messageFactory = account.getMessageFactory();
    ArrayList params = new ArrayList();
    params.add(new BasicNameValuePair("To", "+16464152856")); // Replace with a valid phone number for your account.
    params.add(new BasicNameValuePair("From", "+19899320208")); // Replace with a valid phone number for your account.
    params.add(new BasicNameValuePair("Body", "LOL!"));
    Message sms = messageFactory.create(params);
}

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");

    System.out.println(arrayList.size());

    arrayList.clear();/*w  w w .  java  2s .c  o m*/

    System.out.println(arrayList.size());

}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(20);
    arrlist.add(40);//from w  w w  .  j ava 2s .c om
    arrlist.add(10);
    arrlist.add(15);
    arrlist.add(25);

    Object[] ob = arrlist.toArray();

    System.out.println(Arrays.toString(ob));

}

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) {
    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) {

    ArrayList<String> aList = new ArrayList<String>();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    Iterator itr = aList.iterator();

    // iterate through the ArrayList values using Iterator's hasNext and next methods

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }//from   w  w w  .  j  av  a  2  s.  c  o  m
}

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 w  w. ja  v a2  s .c  o  m

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

    System.out.println(index);
}