Re: Newbie: iterating two collections
- From: heysc0tt@xxxxxxxxx
- Date: 30 Oct 2006 16:14:28 -0800
On Oct 30, 3:34 pm, "u...@xxxxxxxxx" <u...@xxxxxxxxx> wrote:
I have two ArrayLists: List<Boolean> A and List<T> B with same size. I
want something like
for (int i =0; i < A.size(); i++) { B[i].booleanValue =
A[i].booleanValue); }. Just one to one value set. I am pretty new to
iterators. Can I use foreach in java for that? Any decent approach
instead of nested loops?
Ok so what I understand you want is an iterator that will set all
boolean values in list B to be the same as list A. I am assuming the
type of list B (T) is actually Boolean, if not you can change the
setter. As far as the iterator, you were close.
Here is a simple example:
for(int i; i<A.size(); i++)
{
B.set(i, A.get(i));
}
This assumes the List B is already has elements which you're replacing
with the elements in A. If List B is empty you could just use the add
method instead:
for(int i; i<A.size(); i++)
{
B.add(A.get(i));
}
Scott
.
- References:
- Newbie: iterating two collections
- From: usgog@xxxxxxxxx
- Newbie: iterating two collections
- Prev by Date: Re: Problem in the Getting Index possition in JAVA
- Next by Date: Re: rmi application thru NAT
- Previous by thread: Newbie: iterating two collections
- Next by thread: Re: Newbie: iterating two collections
- Index(es):
Relevant Pages
|