Syntax:
ArrayList list = new ArrayList();
Example:
import java.util.ArrayList;
public class MyArrayList {
public static void main(String[] args) {
Seller sel = new Seller();
Buyer buy = new Buyer();
// declare an array list of type Seller
ArrayList
list.add(sel); // add object of type Seller which is permisible
list.add(buy); // this statement will give an error
}
}
source: java-tips.org
No comments:
Post a Comment