• Post Reply Bookmark Topic Watch Topic
  • New Topic

iterating over an arraylist of a perticular class type  RSS feed

 
Deepaks Deshpande
Ranch Hand
Posts: 114
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am creating a tree structure using JSON Object,I have a class (bean class called Tree) where in i have 3 attributes namely id, parent id, title. In another java class i connect to a database and retrieve these values and store it in a arraylist of type <Tree>. Now i have to assign individual attributes like id ,parent id and title to the corresponding JSON objects. How do i iterate through this arraylist and get these individual values?


Thanks in advance.
Deepak
 
Kulbir Java
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepak

I think you should set the values in a bean class then store the bean object in arraylist. Later when you get the obejct from arraylist then you can call the individaul methods.

for examle:
class MyBean {
String id,name;
MyBean(String Id,String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name
}
}

Get the values from Database and set to the bean.
add the bean object to the arraylist
later get the object
cast to the bean and call the method like bean.getId() etc

Hope this helps.

Regards
Kulbir

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!