File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes List interface in Collection Framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "List interface in Collection Framework" Watch "List interface in Collection Framework" New topic

List interface in Collection Framework

Ajay Singh Rathore

Joined: Nov 20, 2007
Posts: 2
can anyone explain this syntax.

List<List<Integer>> table = new ArrayList<List<Integer>>();

what is the meaning of this syntax.
Santhi Bharath
Ranch Hand

Joined: Jun 03, 2008
Posts: 75
up to my knowledge that is list of integer lists.

tables list contains lists of integers

thanks and regards<br />Santhi Bharath<br />SCJP 5.0, SCWCD 5.0
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

Hi Ajayr! Welcome to Javaranch.

Santhi is right. your reference variable table is a list of integer lists.

Lets take a more meaningful example to understand this-

List<List<Planet>> solarSystems = new List<List<Planet>>();

so here we have a list of solar systems, where each solar system has a list of planets. You can add elements to this list as follows

List<Planet> sun = new List<Planet>();
sunPlanets.add(new Planet("Mercury"));
sunPlanets.add(new Planet("Venus"));
sunPlanets.add(new Planet("Earth"));


List <Planet> dogStar = new List<Planet>();
dogStar.add(new Planet("MyPlanet1"));
dogStar.add(new Planet("MyPlanet2"));


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
More than the theoretical explanation, the code looks more understanding...Thanks Ankit !!!
I agree. Here's the link:
subject: List interface in Collection Framework
It's not a secret anymore!