anumalas
asked on
ArrayList to Collection
Hi
I have two DTO's called MyFunctionDTO.java and MyFunctionDTOImpl.java.
In First DTO we have code like bellow
public class MyFunctionDTO implements Serializable{
private MyBlockDTO[] bolck=null;
private String desc = null;
/** And getter, setters of those */
}
In the Second DTO we have code like this
public MyFucntionDTOImpl implements Serializable{
private Collection MyBlockDTO block = null;
private String desc = null;
/** and getter, setters of those*/
}
My Problem is that , i have to take all values from the MyFucntionDTO and convert arrylist into Collection Object and like what we have in ImplDTO. For that i have to write one helper class with one static method , which converts all ArrayList coming form the MyFucntionDTO to Collection Objects. And i have to pass MyFucnitonDTOImpl Objects as a collection to the Action and JSP in UserInterface .. Please Solve this is very urjent
I have two DTO's called MyFunctionDTO.java and MyFunctionDTOImpl.java.
In First DTO we have code like bellow
public class MyFunctionDTO implements Serializable{
private MyBlockDTO[] bolck=null;
private String desc = null;
/** And getter, setters of those */
}
In the Second DTO we have code like this
public MyFucntionDTOImpl implements Serializable{
private Collection MyBlockDTO block = null;
private String desc = null;
/** and getter, setters of those*/
}
My Problem is that , i have to take all values from the MyFucntionDTO and convert arrylist into Collection Object and like what we have in ImplDTO. For that i have to write one helper class with one static method , which converts all ArrayList coming form the MyFucntionDTO to Collection Objects. And i have to pass MyFucnitonDTOImpl Objects as a collection to the Action and JSP in UserInterface .. Please Solve this is very urjent
ASKER
but in my case MyBlockDTO[] is another DTO which contatins some getter and setter. I will explain clearly
MyFunctionDTO contains ---> MyBlockTDO Getter and setters, MyBlockDTO contains--> MyRightsDTO getters and setters
MyFucntionDTOImpl contains pure collection objects.
My problem is that i want to convert MyFucntionDTO objects into pure collection objects. Now we are getting mixed list arraylists form some DTO's and Collections from some DTO's but my UserInterface accepts only collection objects so in my helper class assume like
public static Collection convert(Collection myFuntionDTO)
{
/** Here how to parse myFuncitonDTO.getMyBlockDT O()//whcih will return MyBlockDTO[]. So how to convert that MyBlockDTO[] into Collection Object.
}
Internally MyBlockDTO contatins MyRolesDTO[] getter and setters,
so how to convert those objects form lower lever and centralize those into set of Collection Objects..
MyFunctionDTO contains ---> MyBlockTDO Getter and setters, MyBlockDTO contains--> MyRightsDTO getters and setters
MyFucntionDTOImpl contains pure collection objects.
My problem is that i want to convert MyFucntionDTO objects into pure collection objects. Now we are getting mixed list arraylists form some DTO's and Collections from some DTO's but my UserInterface accepts only collection objects so in my helper class assume like
public static Collection convert(Collection myFuntionDTO)
{
/** Here how to parse myFuncitonDTO.getMyBlockDT
}
Internally MyBlockDTO contatins MyRolesDTO[] getter and setters,
so how to convert those objects form lower lever and centralize those into set of Collection Objects..
Collection c = Arrays.asList(myFuncitonDT O.getMyBlo ckDTO());
I think
Collection c = myFuncitonDTO.getMyBlockDT O(); will do directly.
Collection c = myFuncitonDTO.getMyBlockDT
ASKER
Hi Shivaspk
This will not work for me. Objects solution is some what acceptable for my problem.....
This will not work for me. Objects solution is some what acceptable for my problem.....
You want to store the values from the MyBlockDTO[] array in the MyFunctionDTO class to the MyBlockDTO collection in the MyFucntionDTOImpl class?
MyFunctionDTOImpl obj = new MyFucntionDTOImpl () ;
obj.setMyBlockDTO ( Collections.asList ( myFunctionDTOObject.getMyB lockDTO () ) ) ;
MyFunctionDTOImpl obj = new MyFucntionDTOImpl () ;
obj.setMyBlockDTO ( Collections.asList ( myFunctionDTOObject.getMyB
ASKER
Hi
I have one Collection like follow.
Collection webCollection = blockElements.getWebElemen ts();
How to convert directly that webCollection in to webArray[]. With out using iterator and loops.
Is there any quick solution??
I have one Collection like follow.
Collection webCollection = blockElements.getWebElemen
How to convert directly that webCollection in to webArray[]. With out using iterator and loops.
Is there any quick solution??
webArray[] array = webCollection.toArray ( new webArray[] {} ) ;
ASKER
what are the required imports to use webArray[]. caon you explain more clearly?? thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My problem is like
I have 2 classes called A and B of same structure. Class A returns Collection Object. And Class B uses Array. Can I convert Class A's Collection Object into Class B's Array object. Is it Possible? If yes what is the procedure
I have 2 classes called A and B of same structure. Class A returns Collection Object. And Class B uses Array. Can I convert Class A's Collection Object into Class B's Array object. Is it Possible? If yes what is the procedure
Does the class A's collection hold the same type of objects which class B's array is supposed to hold? If yes, then you can do it.
ASKER
These are my two classes.
Pubilc class A implements Serializabel{
private Collection elements = null;
public void setElements(Collection elements)
{
this.elements = elements;
}
public Collection getElements(){
return elements; }
}
public class B implements Serializable{
private Elements[] elements = null;
public void setElements(Elements[] elements)
{
this.elements = elements;
}
public Elements[] getElements(){
return elements; }
}
So How to convert Class A's Elements Collection object into Class B's Element[] object.
Pubilc class A implements Serializabel{
private Collection elements = null;
public void setElements(Collection elements)
{
this.elements = elements;
}
public Collection getElements(){
return elements; }
}
public class B implements Serializable{
private Elements[] elements = null;
public void setElements(Elements[] elements)
{
this.elements = elements;
}
public Elements[] getElements(){
return elements; }
}
So How to convert Class A's Elements Collection object into Class B's Element[] object.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you need to convert an array to a Collection use:
Collection c = Arrays.asList(myarray);