java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.util arrow How to use generic ArrayList
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use generic ArrayList E-mail
User Rating: / 130
PoorBest 

JDK 5.0 provides typed array list. Before JDK 5.0 Array List store the objects of type Object. But now type of the elements of an ArrayList can be specified.

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<Seller> list = new ArrayList<Seller>();
    list.add(sel)// add object of type Seller which is permisible
    list.add(buy);  // this statement will give an error
   }
}

 Related Tips

 
< Prev   Next >
 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.