• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which collection object is suitable ?  RSS feed

 
Raghu Sha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data available in DB are as follows.

Std. Id Name marks

10 101 XYZ 70
10 102 XYZ 60
10 103 XYZ 50
10 104 XYZ 50
10 105 XYZ 60
10 106 XYZ 70


11 201 XTZ 70
11 202 XYZ 70
11 203 RYZ 70
11 204 XYZ 70

12 301 ABZ 70
12 302 ZDZ 70
12 303 XYZ 70


Used the below query and stored into ArrayList
select std,id,name,marks from student;


Need to display in below format.
10

Id Name marks
101 XYZ 70
102 XYZ 60
103 XYZ 50
104 XYZ 50
105 XYZ 60
106 XYZ 70

11
Id Name marks
201 XTZ 70
202 XYZ 70
203 RYZ 70
204 XYZ 70

12

Id Name marks
301 ABZ 70
302 ZDZ 70
303 XYZ 70

How to iterate over ArrayList?
In which collection object need to use?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barring other requirements, any List implementation should do. So ArrayList would be fine. What you want to store in that List is probably Student objects that encapsulate those 4 values.

In which collection object need to use?

What do you mean by that? An ArrayList *is* a collection. You can iterate over it using the enhanced for-loop syntax, or you can read through the javadocs of the List interface to see of there are any methods that suggest themselves.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!