A2003822018 - 21789 - 17 - 2018 - 09. ArrayList
A2003822018 - 21789 - 17 - 2018 - 09. ArrayList
Topic: ArrayList
Introduction
• Standard Java arrays are of a fixed length.
boolean add(Object o)
• Appends the specified element to the end of this list.
boolean remove(Object o)
• Removes the first specified object present in the arraylist.
int size()
• Returns the number of elements in the list.
boolean contains(Object o)
• Returns true if this list contains the specified element.
int indexOf(Object o)
• Returns the index in this list of the first occurrence of the specified
element, or -1 if the List does not contain the element.
int lastIndexOf(Object o)
• Returns the index in this list of the last occurrence of the specified
element, or -1.
void ensureCapacity(int minCapacity)
• Increases the capacity of this ArrayList instance, if necessary,
to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
void trimToSize()
• reduces the size of an arraylist to the number of elements
present in the arraylist.
• import java.util.*;
• class TestCollection2
• {
• public static void main(String args[])
• {
• ArrayList<String> al=new ArrayList<String>();
• al.add("Ravi");
• al.add("Vijay");
• al.add("Ravi");
• al.add("Ajay");
• for(String obj:al)
• System.out.println(obj);
• }
• }