• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List interface in Collection Framework

 
Ajay Singh Rathore
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone explain this syntax.

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

what is the meaning of this syntax.
 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
up to my knowledge that is list of integer lists.

tables list contains lists of integers
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));

solarSystems.add(sun);

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

solarSystems.add(dogStar);
 
Rekha Srinath
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More than the theoretical explanation, the code looks more understanding...Thanks Ankit !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic