arraylist java doc code example
Example 1: java api add
boolean add(E e)
Appends the specified element to the end of this list (optional operation).
Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
Specified by:
add in interface Collection<E>
Parameters:
e - element to be appended to this list
Returns:
true (as specified by Collection.add(E))
Throws:
UnsupportedOperationException - if the add operation is not supported by this list
ClassCastException - if the class of the specified element prevents it from being added to this list
NullPointerException - if the specified element is null and this list does not permit null elements
IllegalArgumentException - if some property of this element prevents it from being added to this list
Example 2: java arraylist
import java.util.List;
import java.util.ArrayList;
List l = new ArrayList();
ArrayList a = new ArrayList();
List<String> l = new ArrayList<String>();
ArrayList<Integer> a = new ArrayList<Integer>();
List<Double> l = new ArrayList<Double>(5);
Example 3: arraylist in java
import java.util.ArrayList;
public class ArrayListExample
{
public static void main(String[] args)
{
int num = 14;
ArrayList<Integer> al = new ArrayList<Integer>(num);
for(int a = 1; a <= num; a++)
{
al.add(a);
}
System.out.println(al);
al.remove(7);
System.out.println(al);
for(int a = 0; a < al.size(); a++)
{
System.out.print(al.get(a) + " ");
}
}
}
Example 4: arraylist java methds
import java.util.ArrayList;
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(0);
myList.remove(0);
myList.size();
myList.get(0);
Example 5: oracle arraylist
public class ArrayList<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable