ArrayList in Java with example Collections framework
ArrayList which implements the List Interface which belongs to the Collections Framework. ArrayList is very fast and ease of use. So developers prefer ArrayList over Arrays in java.
Advantages:
Output: -
Size of list before removing2
Size of list 1
Important Methods belongs to ArrayList:
ArrayList which implements the List Interface which belongs to the Collections Framework. ArrayList is very fast and ease of use. So developers prefer ArrayList over Arrays in java.
Advantages:
- Other than Arrays ArrayList can increase or decrease its size based on the data size.
- Fast so developers prefer ArrayList
Example:
/**
* author: JOBBERINDIA
*/
package com.jobberindia;
import java.util.*;
/**
* @author user
*
*/
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List<String> list = new ArrayList<String>();
list.add("Hello");
list.add("World");
System.out.println("Size of list before removing"+list.size());
list.remove("Hello");
System.out.println("Size of list "+list.size());
}
}
Size of list before removing2
Size of list 1
Important Methods belongs to ArrayList:
- list.add(arg0);
- list.add(arg0, arg1);
- list.addAll(arg0);
- list.addAll(arg0, arg1);
- list.clear();
- list.contains(arg0);
- list.containsAll(arg0);
- list.containsAll(arg0);
- list.equals(arg0);
- list.get(arg0);
- list.size();
- list.isEmpty();
- list.lastIndexOf(arg0);
- list.remove(arg0);
- list.removeAll(arg0);
- list.toArray();
- list.toString();
No comments:
Post a Comment