• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert one Object to another Object  RSS feed

 
Bhanu Teja
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
This is Bhanu Teja M. I have a problem with an object. Actually i have to convert an object into another object. Here in my Category object contains a list of categories (subcategories). The main issues in this code is we have to convert the all subcategories (Category objects) into CatgoryUI.



When you display the category list with in ul and li in html view it will display like below. And after converting into CategoryUI object if print the list it should also this play in the same way. So, can any please give any suggestions that how to convert the Category into CategoryUI.



Thanks & Regards
Bhanu Teja M.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your CategoryUI class looks exactly the same as your Category class. The only thing that's different is the class name. Why do you need two classes at all? (Or is this not exactly your real code, and are there more differences between the classes in your real code?).

So, is your question about how to implement the convertCategories method?

It will be straightforward: loop through the list of Category objects, and for each one, create a CategoryUI object that you initialize with the values in the Category object, and put the CategoryUI object in a new list. At the end of the method, return the list of CategoryUI objects.

Try writing the method yourself, and if you still have trouble with it, show us what you wrote and we'll help you complete it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!