You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vinita Keswani <vi...@yahoo.com> on 2003/11/17 19:11:33 UTC
How to iterate over two collections ?
Hello,
Could anyone please tell me if there is a workaround for iterating over two collections at the same time when both have the same key but different values?
For eg: Descr, Cost,Volume....
Two maps one is - costMap which has descr and cost
and another one is - volMap which has descr and volume.
Please help
Vinita
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Re: How to iterate over two collections ?
Posted by Vinita Keswani <vi...@yahoo.com>.
Thanks again...
Yes I have to lookup using the key ..that will work fine..Thanks again.
Kris Schneider <kr...@dotech.com> wrote:
I think the code I provided does what you were asking for, but maybe I'm missing
something. Perhaps adding comments to my example will help:
Quoting Vinita Keswani :
> Thanks but in any case I have to create an iterator to loop thru the
> maps.What I want to do is to have one loop and to pick up value entries from
> another - yes may be I can try using lookups using key???
>
> Kris Schneider wrote:With JSTL:
>
>
>
>
>
>
> Quoting Brice Ruth
> :
>
> > You could loop over one collection, exposing the varStatus, which
> > contains the key, and use the key to look up in the second map ... I
> think?
> >
> > Vinita Keswani wrote:
> >
> > >Hello,
> > >
> > >Could anyone please tell me if there is a workaround for iterating over
> two
> > collections at the same time when both have the same key but different
> > values?
> > >
> > >For eg: Descr, Cost,Volume....
> > >Two maps one is - costMap which has descr and cost
> > >and another one is - volMap which has descr and volume.
> > >
> > >Please help
> > >
> > >Vinita
> > >
> > >
> > >---------------------------------
> > >Do you Yahoo!?
> > >Protect your identity with Yahoo! Mail AddressGuard
> > >
> > >
> >
> > --
> > Brice D. Ruth
> > Sr. IT Analyst
> > Fiskars Brands, Inc.
>
> --
> Kris Schneider
> D.O.Tech
--
Kris Schneider
D.O.Tech
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Re: How to iterate over two collections ?
Posted by Kris Schneider <kr...@dotech.com>.
I think the code I provided does what you were asking for, but maybe I'm missing
something. Perhaps adding comments to my example will help:
<%-- iterate through costMap, "entry" will be an instance of Map.Entry --%>
<%-- Map.Entry exposes two properties: "key" and "value" --%>
<c:forEach var="entry" items="${costMap}">
<%-- output value for costMap entry --%>
<c:out value="${entry.value}"/>
<%-- output value for volMap entry --%>
<c:out value="${volMap[entry.key]}"/>
</c:forEach>
Quoting Vinita Keswani <vi...@yahoo.com>:
> Thanks but in any case I have to create an iterator to loop thru the
> maps.What I want to do is to have one loop and to pick up value entries from
> another - yes may be I can try using lookups using key???
>
> Kris Schneider <kr...@dotech.com> wrote:With JSTL:
>
>
>
>
>
>
> Quoting Brice Ruth
> :
>
> > You could loop over one collection, exposing the varStatus, which
> > contains the key, and use the key to look up in the second map ... I
> think?
> >
> > Vinita Keswani wrote:
> >
> > >Hello,
> > >
> > >Could anyone please tell me if there is a workaround for iterating over
> two
> > collections at the same time when both have the same key but different
> > values?
> > >
> > >For eg: Descr, Cost,Volume....
> > >Two maps one is - costMap which has descr and cost
> > >and another one is - volMap which has descr and volume.
> > >
> > >Please help
> > >
> > >Vinita
> > >
> > >
> > >---------------------------------
> > >Do you Yahoo!?
> > >Protect your identity with Yahoo! Mail AddressGuard
> > >
> > >
> >
> > --
> > Brice D. Ruth
> > Sr. IT Analyst
> > Fiskars Brands, Inc.
>
> --
> Kris Schneider
> D.O.Tech
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: How to iterate over two collections ?
Posted by Vinita Keswani <vi...@yahoo.com>.
Thanks but in any case I have to create an iterator to loop thru the maps.What I want to do is to have one loop and to pick up value entries from another - yes may be I can try using lookups using key???
Kris Schneider <kr...@dotech.com> wrote:With JSTL:
Quoting Brice Ruth
:
> You could loop over one collection, exposing the varStatus, which
> contains the key, and use the key to look up in the second map ... I think?
>
> Vinita Keswani wrote:
>
> >Hello,
> >
> >Could anyone please tell me if there is a workaround for iterating over two
> collections at the same time when both have the same key but different
> values?
> >
> >For eg: Descr, Cost,Volume....
> >Two maps one is - costMap which has descr and cost
> >and another one is - volMap which has descr and volume.
> >
> >Please help
> >
> >Vinita
> >
> >
> >---------------------------------
> >Do you Yahoo!?
> >Protect your identity with Yahoo! Mail AddressGuard
> >
> >
>
> --
> Brice D. Ruth
> Sr. IT Analyst
> Fiskars Brands, Inc.
--
Kris Schneider
D.O.Tech
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Re: How to iterate over two collections ?
Posted by Kris Schneider <kr...@dotech.com>.
With JSTL:
<c:forEach var="entry" items="${costMap}">
<c:out value="${entry.value}"/>
<c:out value="${volMap[entry.key]}"/>
</c:forEach>
Quoting Brice Ruth <br...@fiskars.com>:
> You could loop over one collection, exposing the varStatus, which
> contains the key, and use the key to look up in the second map ... I think?
>
> Vinita Keswani wrote:
>
> >Hello,
> >
> >Could anyone please tell me if there is a workaround for iterating over two
> collections at the same time when both have the same key but different
> values?
> >
> >For eg: Descr, Cost,Volume....
> >Two maps one is - costMap which has descr and cost
> >and another one is - volMap which has descr and volume.
> >
> >Please help
> >
> >Vinita
> >
> >
> >---------------------------------
> >Do you Yahoo!?
> >Protect your identity with Yahoo! Mail AddressGuard
> >
> >
>
> --
> Brice D. Ruth
> Sr. IT Analyst
> Fiskars Brands, Inc.
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: How to iterate over two collections ?
Posted by Brice Ruth <br...@fiskars.com>.
You could loop over one collection, exposing the varStatus, which
contains the key, and use the key to look up in the second map ... I think?
Vinita Keswani wrote:
>Hello,
>
>Could anyone please tell me if there is a workaround for iterating over two collections at the same time when both have the same key but different values?
>
>For eg: Descr, Cost,Volume....
>Two maps one is - costMap which has descr and cost
>and another one is - volMap which has descr and volume.
>
>Please help
>
>Vinita
>
>
>---------------------------------
>Do you Yahoo!?
>Protect your identity with Yahoo! Mail AddressGuard
>
>
--
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: How to iterate over two collections ?
Posted by Rick Reumann <st...@reumann.net>.
Vinita Keswani wrote:
> Hello,
>
> Could anyone please tell me if there is a workaround for iterating
> over two collections at the same time when both have the same key but
> different values?
>
> For eg: Descr, Cost,Volume.... Two maps one is - costMap which has
> descr and cost and another one is - volMap which has descr and
> volume.
Here's an example using JSTL that I just tested...
<%
java.util.HashMap costMap = new java.util.HashMap();
costMap.put( "foo", "costFoo" );
costMap.put( "bar", "costBar" );
java.util.HashMap volMap = new java.util.HashMap();
volMap.put( "foo", "volFoo" );
volMap.put( "bar", "volBar" );
pageContext.setAttribute("costMap", costMap );
pageContext.setAttribute("volMap", volMap );
%>
<c:forEach items="${costMap}" var="costItem">
Cost Desc: <c:out value="${costItem.key}"/><br>
Cost Value: <c:out value="${costItem.value}"/><br>
Vol Value: <c:out value="${volMap[costItem.key]}"/><br>
----<br>
</c:forEach>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org